Search in sources :

Example 1 with EntityBasedCompositionAttribute

use of org.hibernate.tuple.entity.EntityBasedCompositionAttribute in project hibernate-orm by hibernate.

the class PropertyFactory method buildEntityBasedAttribute.

/**
	 * Generate a non-identifier (and non-version) attribute based on the given mapped property from the given entity
	 *
	 * @param property The mapped property.
	 * @param lazyAvailable Is property lazy loading currently available.
	 *
	 * @return The appropriate NonIdentifierProperty definition.
	 */
public static NonIdentifierAttribute buildEntityBasedAttribute(EntityPersister persister, SessionFactoryImplementor sessionFactory, int attributeNumber, Property property, boolean lazyAvailable) {
    final Type type = property.getValue().getType();
    final NonIdentifierAttributeNature nature = decode(type);
    // we need to dirty check collections, since they can cause an owner
    // version number increment
    // we need to dirty check many-to-ones with not-found="ignore" in order 
    // to update the cache (not the database), since in this case a null
    // entity reference can lose information
    boolean alwaysDirtyCheck = type.isAssociationType() && ((AssociationType) type).isAlwaysDirtyChecked();
    switch(nature) {
        case BASIC:
            {
                return new EntityBasedBasicAttribute(persister, sessionFactory, attributeNumber, property.getName(), type, new BaselineAttributeInformation.Builder().setLazy(lazyAvailable && property.isLazy()).setInsertable(property.isInsertable()).setUpdateable(property.isUpdateable()).setValueGenerationStrategy(property.getValueGenerationStrategy()).setNullable(property.isOptional()).setDirtyCheckable(alwaysDirtyCheck || property.isUpdateable()).setVersionable(property.isOptimisticLocked()).setCascadeStyle(property.getCascadeStyle()).setFetchMode(property.getValue().getFetchMode()).createInformation());
            }
        case COMPOSITE:
            {
                return new EntityBasedCompositionAttribute(persister, sessionFactory, attributeNumber, property.getName(), (CompositeType) type, new BaselineAttributeInformation.Builder().setLazy(lazyAvailable && property.isLazy()).setInsertable(property.isInsertable()).setUpdateable(property.isUpdateable()).setValueGenerationStrategy(property.getValueGenerationStrategy()).setNullable(property.isOptional()).setDirtyCheckable(alwaysDirtyCheck || property.isUpdateable()).setVersionable(property.isOptimisticLocked()).setCascadeStyle(property.getCascadeStyle()).setFetchMode(property.getValue().getFetchMode()).createInformation());
            }
        case ENTITY:
        case ANY:
        case COLLECTION:
            {
                return new EntityBasedAssociationAttribute(persister, sessionFactory, attributeNumber, property.getName(), (AssociationType) type, new BaselineAttributeInformation.Builder().setLazy(lazyAvailable && property.isLazy()).setInsertable(property.isInsertable()).setUpdateable(property.isUpdateable()).setValueGenerationStrategy(property.getValueGenerationStrategy()).setNullable(property.isOptional()).setDirtyCheckable(alwaysDirtyCheck || property.isUpdateable()).setVersionable(property.isOptimisticLocked()).setCascadeStyle(property.getCascadeStyle()).setFetchMode(property.getValue().getFetchMode()).createInformation());
            }
        default:
            {
                throw new HibernateException("Internal error");
            }
    }
}
Also used : CompositeType(org.hibernate.type.CompositeType) VersionType(org.hibernate.type.VersionType) AssociationType(org.hibernate.type.AssociationType) Type(org.hibernate.type.Type) EntityBasedAssociationAttribute(org.hibernate.tuple.entity.EntityBasedAssociationAttribute) AssociationType(org.hibernate.type.AssociationType) EntityBasedCompositionAttribute(org.hibernate.tuple.entity.EntityBasedCompositionAttribute) HibernateException(org.hibernate.HibernateException) EntityBasedBasicAttribute(org.hibernate.tuple.entity.EntityBasedBasicAttribute) CompositeType(org.hibernate.type.CompositeType)

Aggregations

HibernateException (org.hibernate.HibernateException)1 EntityBasedAssociationAttribute (org.hibernate.tuple.entity.EntityBasedAssociationAttribute)1 EntityBasedBasicAttribute (org.hibernate.tuple.entity.EntityBasedBasicAttribute)1 EntityBasedCompositionAttribute (org.hibernate.tuple.entity.EntityBasedCompositionAttribute)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