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");
}
}
}
Aggregations