/** * Generates the attribute representation of the identifier for a given entity mapping. * * @param mappedEntity The mapping definition of the entity. * @param generator The identifier value generator to use for this identifier. * @return The appropriate IdentifierProperty definition. */ public static IdentifierProperty buildIdentifierAttribute( PersistentClass mappedEntity, IdentifierGenerator generator) { String mappedUnsavedValue = mappedEntity.getIdentifier().getNullValue(); Type type = mappedEntity.getIdentifier().getType(); Property property = mappedEntity.getIdentifierProperty(); IdentifierValue unsavedValue = UnsavedValueFactory.getUnsavedIdentifierValue( mappedUnsavedValue, getGetter(property), type, getConstructor(mappedEntity)); if (property == null) { // this is a virtual id property... return new IdentifierProperty( type, mappedEntity.hasEmbeddedIdentifier(), mappedEntity.hasIdentifierMapper(), unsavedValue, generator); } else { return new IdentifierProperty( property.getName(), property.getNodeName(), type, mappedEntity.hasEmbeddedIdentifier(), unsavedValue, generator); } }
/** * Generates a VersionProperty representation for an entity mapping given its version mapping * Property. * * @param property The version mapping Property. * @param lazyAvailable Is property lazy loading currently available. * @return The appropriate VersionProperty definition. */ public static VersionProperty buildVersionProperty( EntityPersister persister, SessionFactoryImplementor sessionFactory, int attributeNumber, Property property, boolean lazyAvailable) { String mappedUnsavedValue = ((KeyValue) property.getValue()).getNullValue(); VersionValue unsavedValue = UnsavedValueFactory.getUnsavedVersionValue( mappedUnsavedValue, getGetter(property), (VersionType) property.getType(), getConstructor(property.getPersistentClass())); boolean lazy = lazyAvailable && property.isLazy(); return new VersionProperty( persister, sessionFactory, attributeNumber, property.getName(), property.getValue().getType(), new BaselineAttributeInformation.Builder() .setLazy(lazy) .setInsertable(property.isInsertable()) .setUpdateable(property.isUpdateable()) .setValueGenerationStrategy(property.getValueGenerationStrategy()) .setNullable(property.isOptional()) .setDirtyCheckable(property.isUpdateable() && !lazy) .setVersionable(property.isOptimisticLocked()) .setCascadeStyle(property.getCascadeStyle()) .createInformation(), unsavedValue); }