Search in sources :

Example 1 with IdentifierValue

use of org.hibernate.engine.spi.IdentifierValue in project hibernate-orm by hibernate.

the class PropertyFactory method buildIdentifierAttribute.

/**
	 * 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(), type, mappedEntity.hasEmbeddedIdentifier(), unsavedValue, generator);
    }
}
Also used : CompositeType(org.hibernate.type.CompositeType) VersionType(org.hibernate.type.VersionType) AssociationType(org.hibernate.type.AssociationType) Type(org.hibernate.type.Type) IdentifierValue(org.hibernate.engine.spi.IdentifierValue) Property(org.hibernate.mapping.Property) VersionProperty(org.hibernate.tuple.entity.VersionProperty)

Aggregations

IdentifierValue (org.hibernate.engine.spi.IdentifierValue)1 Property (org.hibernate.mapping.Property)1 VersionProperty (org.hibernate.tuple.entity.VersionProperty)1 AssociationType (org.hibernate.type.AssociationType)1 CompositeType (org.hibernate.type.CompositeType)1 Type (org.hibernate.type.Type)1 VersionType (org.hibernate.type.VersionType)1