HHH-18506 Improve flush performance by reducing itable stubs

This commit is contained in:
Christian Beikov 2024-08-20 12:54:43 +02:00
parent d4740a9bc8
commit 94b444b4d8
37 changed files with 245 additions and 172 deletions

View File

@ -15,8 +15,11 @@ import org.hibernate.AssertionFailure;
import org.hibernate.Hibernate; import org.hibernate.Hibernate;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.AnyType;
import org.hibernate.type.CollectionType; import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType; import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import jakarta.validation.Path; import jakarta.validation.Path;
@ -54,17 +57,17 @@ public class HibernateTraversableResolver implements TraversableResolver {
private void addAssociationsToTheSetForOneProperty(String name, Type type, String prefix, SessionFactoryImplementor factory) { private void addAssociationsToTheSetForOneProperty(String name, Type type, String prefix, SessionFactoryImplementor factory) {
if ( type.isCollectionType() ) { if ( type instanceof CollectionType ) {
CollectionType collType = (CollectionType) type; CollectionType collType = (CollectionType) type;
Type assocType = collType.getElementType( factory ); Type assocType = collType.getElementType( factory );
addAssociationsToTheSetForOneProperty(name, assocType, prefix, factory); addAssociationsToTheSetForOneProperty(name, assocType, prefix, factory);
} }
//ToOne association //ToOne association
else if ( type.isEntityType() || type.isAnyType() ) { else if ( type instanceof EntityType || type instanceof AnyType ) {
associations.add( prefix + name ); associations.add( prefix + name );
} }
else if ( type.isComponentType() ) { else if ( type instanceof ComponentType ) {
CompositeType componentType = (CompositeType) type; ComponentType componentType = (ComponentType) type;
addAssociationsToTheSetForAllProperties( addAssociationsToTheSetForAllProperties(
componentType.getPropertyNames(), componentType.getPropertyNames(),
componentType.getSubtypes(), componentType.getSubtypes(),

View File

@ -16,6 +16,7 @@ import org.hibernate.engine.spi.EntityKey;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.metamodel.mapping.AttributeMapping; import org.hibernate.metamodel.mapping.AttributeMapping;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.CollectionType;
import org.hibernate.type.CompositeType; import org.hibernate.type.CompositeType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
@ -65,7 +66,7 @@ public class EnhancementAsProxyLazinessInterceptor extends AbstractLazyLoadInter
collectionAttributeNames = new HashSet<>(); collectionAttributeNames = new HashSet<>();
for ( int i = 0; i < propertyTypes.length; i++ ) { for ( int i = 0; i < propertyTypes.length; i++ ) {
Type propertyType = propertyTypes[i]; Type propertyType = propertyTypes[i];
if ( propertyType.isCollectionType() ) { if ( propertyType instanceof CollectionType ) {
collectionAttributeNames.add( propertyNames[i] ); collectionAttributeNames.add( propertyNames[i] );
} }
} }

View File

@ -7,6 +7,7 @@
package org.hibernate.bytecode.enhance.spi.interceptor; package org.hibernate.bytecode.enhance.spi.interceptor;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.type.CollectionType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
/** /**
@ -21,7 +22,7 @@ public class LazyAttributeDescriptor {
int lazyIndex) { int lazyIndex) {
String fetchGroupName = property.getLazyGroup(); String fetchGroupName = property.getLazyGroup();
if ( fetchGroupName == null ) { if ( fetchGroupName == null ) {
fetchGroupName = property.getType().isCollectionType() fetchGroupName = property.getType() instanceof CollectionType
? property.getName() ? property.getName()
: "DEFAULT"; : "DEFAULT";
} }

View File

@ -27,13 +27,18 @@ import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.type.AnyType;
import org.hibernate.type.AssociationType; import org.hibernate.type.AssociationType;
import org.hibernate.type.CollectionType; import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType; import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType; import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType; import org.hibernate.type.EntityType;
import org.hibernate.type.ForeignKeyDirection;
import org.hibernate.type.ManyToOneType; import org.hibernate.type.ManyToOneType;
import org.hibernate.type.OneToOneType; import org.hibernate.type.OneToOneType;
import org.hibernate.type.OneToOneType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import static org.hibernate.engine.internal.ManagedTypeHelper.isHibernateProxy; import static org.hibernate.engine.internal.ManagedTypeHelper.isHibernateProxy;
@ -130,7 +135,7 @@ public final class Cascade {
// parent was not in the PersistenceContext // parent was not in the PersistenceContext
continue; continue;
} }
if ( type.isCollectionType() ) { if ( type instanceof CollectionType ) {
// CollectionType#getCollection gets the PersistentCollection // CollectionType#getCollection gets the PersistentCollection
// that corresponds to the uninitialized collection from the // that corresponds to the uninitialized collection from the
// PersistenceContext. If not present, an uninitialized // PersistenceContext. If not present, an uninitialized
@ -145,13 +150,13 @@ public final class Cascade {
null null
); );
} }
else if ( type.isComponentType() ) { else if ( type instanceof AnyType || type instanceof ComponentType ) {
// Hibernate does not support lazy embeddables, so this shouldn't happen. // Hibernate does not support lazy embeddables, so this shouldn't happen.
throw new UnsupportedOperationException( throw new UnsupportedOperationException(
"Lazy components are not supported." "Lazy components are not supported."
); );
} }
else if ( action.performOnLazyProperty() && type.isEntityType() ) { else if ( action.performOnLazyProperty() && type instanceof EntityType ) {
// Only need to initialize a lazy entity attribute when action.performOnLazyProperty() // Only need to initialize a lazy entity attribute when action.performOnLazyProperty()
// returns true. // returns true.
LazyAttributeLoadingInterceptor interceptor = persister.getBytecodeEnhancementMetadata() LazyAttributeLoadingInterceptor interceptor = persister.getBytecodeEnhancementMetadata()
@ -222,7 +227,7 @@ public final class Cascade {
final boolean isCascadeDeleteEnabled) throws HibernateException { final boolean isCascadeDeleteEnabled) throws HibernateException {
if ( child != null ) { if ( child != null ) {
if ( type.isAssociationType() ) { if ( type instanceof EntityType || type instanceof CollectionType || type instanceof AnyType ) {
final AssociationType associationType = (AssociationType) type; final AssociationType associationType = (AssociationType) type;
final boolean unownedTransient = eventSource.getSessionFactory() final boolean unownedTransient = eventSource.getSessionFactory()
.getSessionFactoryOptions() .getSessionFactoryOptions()
@ -242,7 +247,7 @@ public final class Cascade {
); );
} }
} }
else if ( type.isComponentType() ) { else if ( type instanceof ComponentType ) {
if ( componentPath == null && propertyName != null ) { if ( componentPath == null && propertyName != null ) {
componentPath = new ArrayList<>(); componentPath = new ArrayList<>();
} }
@ -359,8 +364,8 @@ public final class Cascade {
); );
} }
if ( type.isAssociationType() if ( type instanceof CollectionType
&& ( (AssociationType) type ).getForeignKeyDirection().equals(TO_PARENT) ) { || type instanceof OneToOneType && ( (OneToOneType) type ).getForeignKeyDirection() == ForeignKeyDirection.TO_PARENT ) {
// If FK direction is to-parent, we must remove the orphan *before* the queued update(s) // If FK direction is to-parent, we must remove the orphan *before* the queued update(s)
// occur. Otherwise, replacing the association on a managed entity, without manually // occur. Otherwise, replacing the association on a managed entity, without manually
// nulling and flushing, causes FK constraint violations. // nulling and flushing, causes FK constraint violations.
@ -400,7 +405,6 @@ public final class Cascade {
} }
private static boolean isUnownedAssociation(AssociationType associationType, SessionFactoryImplementor factory) { private static boolean isUnownedAssociation(AssociationType associationType, SessionFactoryImplementor factory) {
if ( associationType.isEntityType() ) {
if ( associationType instanceof ManyToOneType ) { if ( associationType instanceof ManyToOneType ) {
final ManyToOneType manyToOne = (ManyToOneType) associationType; final ManyToOneType manyToOne = (ManyToOneType) associationType;
// logical one-to-one + non-null unique key property name indicates unowned // logical one-to-one + non-null unique key property name indicates unowned
@ -411,8 +415,7 @@ public final class Cascade {
// constrained false + non-null unique key property name indicates unowned // constrained false + non-null unique key property name indicates unowned
return oneToOne.isNullable() && oneToOne.getRHSUniqueKeyPropertyName() != null; return oneToOne.isNullable() && oneToOne.getRHSUniqueKeyPropertyName() != null;
} }
} else if ( associationType instanceof CollectionType ) {
else if ( associationType.isCollectionType() ) {
// for collections, we can ask the persister if we're on the inverse side // for collections, we can ask the persister if we're on the inverse side
return ( (CollectionType) associationType ).isInverse( factory ); return ( (CollectionType) associationType ).isInverse( factory );
} }
@ -468,10 +471,10 @@ public final class Cascade {
final CascadeStyle style, final CascadeStyle style,
final T anything, final T anything,
final boolean isCascadeDeleteEnabled) { final boolean isCascadeDeleteEnabled) {
if ( type.isEntityType() || type.isAnyType() ) { if ( type instanceof EntityType || type instanceof AnyType ) {
cascadeToOne( action, eventSource, parent, child, type, style, anything, isCascadeDeleteEnabled ); cascadeToOne( action, eventSource, parent, child, type, style, anything, isCascadeDeleteEnabled );
} }
else if ( type.isCollectionType() ) { else if ( type instanceof CollectionType ) {
cascadeCollection( cascadeCollection(
action, action,
cascadePoint, cascadePoint,
@ -510,7 +513,7 @@ public final class Cascade {
} }
//cascade to current collection elements //cascade to current collection elements
if ( elemType.isEntityType() || elemType.isAnyType() || elemType.isComponentType() ) { if ( elemType instanceof EntityType || elemType instanceof AnyType || elemType instanceof ComponentType ) {
cascadeCollectionElements( cascadeCollectionElements(
action, action,
elementsCascadePoint, elementsCascadePoint,
@ -539,7 +542,7 @@ public final class Cascade {
final CascadeStyle style, final CascadeStyle style,
final T anything, final T anything,
final boolean isCascadeDeleteEnabled) { final boolean isCascadeDeleteEnabled) {
final String entityName = type.isEntityType() final String entityName = type instanceof EntityType
? ( (EntityType) type ).getAssociatedEntityName() ? ( (EntityType) type ).getAssociatedEntityName()
: null; : null;
if ( style.reallyDoCascade( action ) ) { if ( style.reallyDoCascade( action ) ) {
@ -603,7 +606,7 @@ public final class Cascade {
final boolean deleteOrphans = style.hasOrphanDelete() final boolean deleteOrphans = style.hasOrphanDelete()
&& action.deleteOrphans() && action.deleteOrphans()
&& elemType.isEntityType() && elemType instanceof EntityType
&& child instanceof PersistentCollection && child instanceof PersistentCollection
// a newly instantiated collection can't have orphans // a newly instantiated collection can't have orphans
&& ! ( (PersistentCollection<?>) child ).isNewlyInstantiated(); && ! ( (PersistentCollection<?>) child ).isNewlyInstantiated();

View File

@ -16,7 +16,8 @@ import org.hibernate.engine.spi.SelfDirtinessTracker;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.proxy.LazyInitializer; import org.hibernate.proxy.LazyInitializer;
import org.hibernate.type.CompositeType; import org.hibernate.type.AnyType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.EntityType; import org.hibernate.type.EntityType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
@ -106,21 +107,21 @@ public final class ForeignKeys {
if ( value == null ) { if ( value == null ) {
return null; return null;
} }
else if ( type.isEntityType() ) { else if ( type instanceof EntityType ) {
return nullifyEntityType( value, propertyName, (EntityType) type ); return nullifyEntityType( value, propertyName, (EntityType) type );
} }
else if ( type.isAnyType() ) { else if ( type instanceof AnyType ) {
return isNullifiable( null, value) ? null : value; return isNullifiable( null, value) ? null : value;
} }
else if ( type.isComponentType() ) { else if ( type instanceof ComponentType ) {
return nullifyCompositeType( value, propertyName, (CompositeType) type ); return nullifyCompositeType( value, propertyName, (ComponentType) type );
} }
else { else {
return value; return value;
} }
} }
private Object nullifyCompositeType(Object value, String propertyName, CompositeType compositeType) { private Object nullifyCompositeType(Object value, String propertyName, ComponentType compositeType) {
final Object[] subvalues = compositeType.getPropertyValues(value, session ); final Object[] subvalues = compositeType.getPropertyValues(value, session );
final Type[] subtypes = compositeType.getSubtypes(); final Type[] subtypes = compositeType.getSubtypes();
final String[] subPropertyNames = compositeType.getPropertyNames(); final String[] subPropertyNames = compositeType.getPropertyNames();
@ -194,7 +195,7 @@ public final class ForeignKeys {
// more than just initializing the associated entity. // more than just initializing the associated entity.
return isDelete return isDelete
&& value == UNFETCHED_PROPERTY && value == UNFETCHED_PROPERTY
&& type.isEntityType() && type instanceof EntityType
&& !session.getPersistenceContextInternal().isNullifiableEntityKeysEmpty(); && !session.getPersistenceContextInternal().isNullifiableEntityKeysEmpty();
} }
@ -432,7 +433,7 @@ public final class ForeignKeys {
if ( value == null ) { if ( value == null ) {
// do nothing // do nothing
} }
else if ( type.isEntityType() ) { else if ( type instanceof EntityType ) {
final EntityType entityType = (EntityType) type; final EntityType entityType = (EntityType) type;
if ( !isNullable if ( !isNullable
&& !entityType.isOneToOne() && !entityType.isOneToOne()
@ -440,13 +441,13 @@ public final class ForeignKeys {
nonNullableTransientEntities.add( propertyName, value ); nonNullableTransientEntities.add( propertyName, value );
} }
} }
else if ( type.isAnyType() ) { else if ( type instanceof AnyType ) {
if ( !isNullable && nullifier.isNullifiable( null, value ) ) { if ( !isNullable && nullifier.isNullifiable( null, value ) ) {
nonNullableTransientEntities.add( propertyName, value ); nonNullableTransientEntities.add( propertyName, value );
} }
} }
else if ( type.isComponentType() ) { else if ( type instanceof ComponentType ) {
final CompositeType compositeType = (CompositeType) type; final ComponentType compositeType = (ComponentType) type;
final boolean[] subValueNullability = compositeType.getPropertyNullability(); final boolean[] subValueNullability = compositeType.getPropertyNullability();
if ( subValueNullability != null ) { if ( subValueNullability != null ) {
final String[] subPropertyNames = compositeType.getPropertyNames(); final String[] subPropertyNames = compositeType.getPropertyNames();

View File

@ -14,7 +14,9 @@ import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.generator.Generator; import org.hibernate.generator.Generator;
import org.hibernate.type.AnyType;
import org.hibernate.type.CollectionType; import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType; import org.hibernate.type.CompositeType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
@ -144,16 +146,19 @@ public final class Nullability {
* @throws HibernateException error while getting subcomponent values * @throws HibernateException error while getting subcomponent values
*/ */
private String checkSubElementsNullability(Type propertyType, Object value) throws HibernateException { private String checkSubElementsNullability(Type propertyType, Object value) throws HibernateException {
if ( propertyType.isComponentType() ) { if ( propertyType instanceof AnyType ) {
return checkComponentNullability( value, (CompositeType) propertyType ); return checkComponentNullability( value, (AnyType) propertyType );
}
if ( propertyType instanceof ComponentType ) {
return checkComponentNullability( value, (ComponentType) propertyType );
} }
if ( propertyType.isCollectionType() ) { if ( propertyType instanceof CollectionType ) {
// persistent collections may have components // persistent collections may have components
final CollectionType collectionType = (CollectionType) propertyType; final CollectionType collectionType = (CollectionType) propertyType;
final Type collectionElementType = collectionType.getElementType( session.getFactory() ); final Type collectionElementType = collectionType.getElementType( session.getFactory() );
if ( collectionElementType.isComponentType() ) { if ( collectionElementType instanceof ComponentType || collectionElementType instanceof AnyType ) {
// check for all components values in the collection // check for all components values in the collection
final CompositeType componentType = (CompositeType) collectionElementType; final CompositeType componentType = (CompositeType) collectionElementType;
final Iterator<?> itr = getLoadedElementsIterator( session, collectionType, value ); final Iterator<?> itr = getLoadedElementsIterator( session, collectionType, value );
@ -189,7 +194,7 @@ public final class Nullability {
// //
// The more correct fix would be to cascade saves of the many-to-any elements before the Nullability checking // The more correct fix would be to cascade saves of the many-to-any elements before the Nullability checking
if ( compositeType.isAnyType() ) { if ( compositeType instanceof AnyType ) {
return null; return null;
} }

View File

@ -14,6 +14,7 @@ import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.BagType; import org.hibernate.type.BagType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -72,7 +73,7 @@ public class FetchProfile {
final String role = association.getRole(); final String role = association.getRole();
final Type associationType = final Type associationType =
association.getOwner().getPropertyType( association.getAssociationPath() ); association.getOwner().getPropertyType( association.getAssociationPath() );
if ( associationType.isCollectionType() ) { if ( associationType instanceof CollectionType ) {
LOG.tracev( "Handling request to add collection fetch [{0}]", role ); LOG.tracev( "Handling request to add collection fetch [{0}]", role );
// couple of things for which to account in the case of collection // couple of things for which to account in the case of collection

View File

@ -52,7 +52,7 @@ import org.hibernate.metamodel.mapping.internal.EntityCollectionPart;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.proxy.LazyInitializer; import org.hibernate.proxy.LazyInitializer;
import org.hibernate.type.CollectionType; import org.hibernate.type.CollectionType;
import org.hibernate.type.CompositeType; import org.hibernate.type.ComponentType;
import org.hibernate.type.EntityType; import org.hibernate.type.EntityType;
import org.hibernate.type.ForeignKeyDirection; import org.hibernate.type.ForeignKeyDirection;
import org.hibernate.type.Type; import org.hibernate.type.Type;
@ -1167,7 +1167,10 @@ public class ActionQueue {
} }
private void addDirectDependency(Type type, @Nullable Object value, IdentityHashMap<Object, InsertInfo> insertInfosByEntity) { private void addDirectDependency(Type type, @Nullable Object value, IdentityHashMap<Object, InsertInfo> insertInfosByEntity) {
if ( type.isEntityType() && value != null ) { if ( value == null ) {
return;
}
if ( type instanceof EntityType ) {
final EntityType entityType = (EntityType) type; final EntityType entityType = (EntityType) type;
final InsertInfo insertInfo = insertInfosByEntity.get( value ); final InsertInfo insertInfo = insertInfosByEntity.get( value );
if ( insertInfo != null ) { if ( insertInfo != null ) {
@ -1188,7 +1191,7 @@ public class ActionQueue {
} }
} }
} }
else if ( type.isCollectionType() && value != null ) { else if ( type instanceof CollectionType ) {
CollectionType collectionType = (CollectionType) type; CollectionType collectionType = (CollectionType) type;
final PluralAttributeMapping pluralAttributeMapping = insertAction.getSession() final PluralAttributeMapping pluralAttributeMapping = insertAction.getSession()
.getFactory() .getFactory()
@ -1212,9 +1215,9 @@ public class ActionQueue {
} }
} }
} }
else if ( type.isComponentType() && value != null ) { else if ( type instanceof ComponentType ) {
// Support recursive checks of composite type properties for associations and collections. // Support recursive checks of composite type properties for associations and collections.
final CompositeType compositeType = (CompositeType) type; ComponentType compositeType = (ComponentType) type;
final SharedSessionContractImplementor session = insertAction.getSession(); final SharedSessionContractImplementor session = insertAction.getSession();
final Object[] componentValues = compositeType.getPropertyValues( value, session ); final Object[] componentValues = compositeType.getPropertyValues( value, session );
for ( int j = 0; j < componentValues.length; ++j ) { for ( int j = 0; j < componentValues.length; ++j ) {

View File

@ -10,7 +10,9 @@ import org.hibernate.HibernateException;
import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer; import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer;
import org.hibernate.event.spi.EventSource; import org.hibernate.event.spi.EventSource;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.AnyType;
import org.hibernate.type.CollectionType; import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType; import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType; import org.hibernate.type.EntityType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
@ -87,15 +89,18 @@ public abstract class AbstractVisitor {
*/ */
final Object processValue(Object value, Type type) throws HibernateException { final Object processValue(Object value, Type type) throws HibernateException {
if ( type.isCollectionType() ) { if ( type instanceof CollectionType ) {
//even process null collections //even process null collections
return processCollection( value, (CollectionType) type ); return processCollection( value, (CollectionType) type );
} }
else if ( type.isEntityType() ) { else if ( type instanceof EntityType ) {
return processEntity( value, (EntityType) type ); return processEntity( value, (EntityType) type );
} }
else if ( type.isComponentType() ) { else if ( type instanceof ComponentType ) {
return processComponent( value, (CompositeType) type ); return processComponent( value, (ComponentType) type );
}
else if ( type instanceof AnyType ) {
return processComponent( value, (AnyType) type );
} }
else { else {
return null; return null;

View File

@ -47,6 +47,7 @@ import org.hibernate.property.access.internal.PropertyAccessStrategyBackRefImpl;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer; import org.hibernate.proxy.LazyInitializer;
import org.hibernate.type.CollectionType; import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType; import org.hibernate.type.CompositeType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.hibernate.type.TypeHelper; import org.hibernate.type.TypeHelper;
@ -137,15 +138,15 @@ public class DefaultDeleteEventListener implements DeleteEventListener, Callback
private static void deleteOwnedCollections(Type type, Object key, EventSource session) { private static void deleteOwnedCollections(Type type, Object key, EventSource session) {
final MappingMetamodelImplementor mappingMetamodel = session.getFactory().getMappingMetamodel(); final MappingMetamodelImplementor mappingMetamodel = session.getFactory().getMappingMetamodel();
final ActionQueue actionQueue = session.getActionQueue(); final ActionQueue actionQueue = session.getActionQueue();
if ( type.isCollectionType() ) { if ( type instanceof CollectionType ) {
final String role = ( (CollectionType) type ).getRole(); final String role = ( (CollectionType) type ).getRole();
final CollectionPersister persister = mappingMetamodel.getCollectionDescriptor(role); final CollectionPersister persister = mappingMetamodel.getCollectionDescriptor(role);
if ( !persister.isInverse() && !skipRemoval( session, persister, key ) ) { if ( !persister.isInverse() && !skipRemoval( session, persister, key ) ) {
actionQueue.addAction( new CollectionRemoveAction( persister, key, session ) ); actionQueue.addAction( new CollectionRemoveAction( persister, key, session ) );
} }
} }
else if ( type.isComponentType() ) { else if ( type instanceof ComponentType ) {
final Type[] subtypes = ( (CompositeType) type ).getSubtypes(); final Type[] subtypes = ( (ComponentType) type ).getSubtypes();
for ( Type subtype : subtypes ) { for ( Type subtype : subtypes ) {
deleteOwnedCollections( subtype, key, session ); deleteOwnedCollections( subtype, key, session );
} }
@ -459,7 +460,7 @@ public class DefaultDeleteEventListener implements DeleteEventListener, Callback
final String[] propertyNames = persister.getPropertyNames(); final String[] propertyNames = persister.getPropertyNames();
final BytecodeEnhancementMetadata enhancementMetadata = persister.getBytecodeEnhancementMetadata(); final BytecodeEnhancementMetadata enhancementMetadata = persister.getBytecodeEnhancementMetadata();
for ( int i = 0; i < types.length; i++) { for ( int i = 0; i < types.length; i++) {
if ( types[i].isCollectionType() && !enhancementMetadata.isAttributeLoaded( parent, propertyNames[i] ) ) { if ( types[i] instanceof CollectionType && !enhancementMetadata.isAttributeLoaded( parent, propertyNames[i] ) ) {
final CollectionType collectionType = (CollectionType) types[i]; final CollectionType collectionType = (CollectionType) types[i];
final CollectionPersister collectionDescriptor = persister.getFactory().getMappingMetamodel() final CollectionPersister collectionDescriptor = persister.getFactory().getMappingMetamodel()
.getCollectionDescriptor( collectionType.getRole() ); .getCollectionDescriptor( collectionType.getRole() );

View File

@ -41,7 +41,9 @@ import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer; import org.hibernate.proxy.LazyInitializer;
import org.hibernate.stat.spi.StatisticsImplementor; import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.type.AnyType;
import org.hibernate.type.CollectionType; import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType; import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType; import org.hibernate.type.EntityType;
import org.hibernate.type.ForeignKeyDirection; import org.hibernate.type.ForeignKeyDirection;
@ -165,14 +167,14 @@ public class DefaultMergeEventListener
originalId = persister.getIdentifier( entity, source ); originalId = persister.getIdentifier( entity, source );
if ( originalId != null ) { if ( originalId != null ) {
final EntityKey entityKey; final EntityKey entityKey;
if ( persister.getIdentifierType().isComponentType() ) { if ( persister.getIdentifierType() instanceof ComponentType ) {
/* /*
this is needed in case of composite id containing an association with a generated identifier, in such a case this is needed in case of composite id containing an association with a generated identifier, in such a case
generating the EntityKey will cause a NPE when trying to get the hashcode of the null id generating the EntityKey will cause a NPE when trying to get the hashcode of the null id
*/ */
copiedId = copyCompositeTypeId( copiedId = copyCompositeTypeId(
originalId, originalId,
(CompositeType) persister.getIdentifierType(), (ComponentType) persister.getIdentifierType(),
source, source,
copiedAlready copiedAlready
); );
@ -250,7 +252,7 @@ public class DefaultMergeEventListener
final Object[] copyValues = compositeType.getPropertyValues( idCopy ); final Object[] copyValues = compositeType.getPropertyValues( idCopy );
for ( int i = 0; i < subtypes.length; i++ ) { for ( int i = 0; i < subtypes.length; i++ ) {
final Type subtype = subtypes[i]; final Type subtype = subtypes[i];
if ( subtype.isEntityType() ) { if ( subtype instanceof EntityType ) {
// the value of the copy in the MergeContext has the id assigned // the value of the copy in the MergeContext has the id assigned
final Object o = mergeContext.get( propertyValues[i] ); final Object o = mergeContext.get( propertyValues[i] );
if ( o != null ) { if ( o != null ) {
@ -260,8 +262,11 @@ public class DefaultMergeEventListener
copyValues[i] = subtype.deepCopy( propertyValues[i], sessionFactory ); copyValues[i] = subtype.deepCopy( propertyValues[i], sessionFactory );
} }
} }
else if ( subtype.isComponentType() ) { else if ( subtype instanceof AnyType ) {
copyValues[i] = copyCompositeTypeId( propertyValues[i], (CompositeType) subtype, session, mergeContext ); copyValues[i] = copyCompositeTypeId( propertyValues[i], (AnyType) subtype, session, mergeContext );
}
else if ( subtype instanceof ComponentType ) {
copyValues[i] = copyCompositeTypeId( propertyValues[i], (ComponentType) subtype, session, mergeContext );
} }
else { else {
copyValues[i] = subtype.deepCopy( propertyValues[i], sessionFactory ); copyValues[i] = subtype.deepCopy( propertyValues[i], sessionFactory );

View File

@ -36,6 +36,7 @@ import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer; import org.hibernate.proxy.LazyInitializer;
import org.hibernate.type.CollectionType; import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType; import org.hibernate.type.CompositeType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
@ -315,7 +316,7 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
final SessionFactoryImplementor factory = source.getFactory(); final SessionFactoryImplementor factory = source.getFactory();
final MappingMetamodelImplementor metamodel = factory.getRuntimeMetamodels().getMappingMetamodel(); final MappingMetamodelImplementor metamodel = factory.getRuntimeMetamodels().getMappingMetamodel();
for ( Type type : types ) { for ( Type type : types ) {
if ( type.isCollectionType() ) { if ( type instanceof CollectionType ) {
final String role = ((CollectionType) type).getRole(); final String role = ((CollectionType) type).getRole();
final CollectionPersister collectionPersister = metamodel.getCollectionDescriptor( role ); final CollectionPersister collectionPersister = metamodel.getCollectionDescriptor( role );
if ( collectionPersister.hasCache() ) { if ( collectionPersister.hasCache() ) {
@ -331,8 +332,9 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
actionQueue.registerProcess( (success, session) -> cache.unlockItem( session, ck, lock ) ); actionQueue.registerProcess( (success, session) -> cache.unlockItem( session, ck, lock ) );
} }
} }
else if ( type.isComponentType() ) { else if ( type instanceof ComponentType ) {
final CompositeType compositeType = (CompositeType) type; // Only components can contain collections
ComponentType compositeType = (ComponentType) type;
evictCachedCollections( compositeType.getSubtypes(), id, source ); evictCachedCollections( compositeType.getSubtypes(), id, source );
} }
} }

View File

@ -173,7 +173,7 @@ public final class IdentifierGeneratorHelper {
private static EntityType entityType(String propertyName, EntityPersister entityDescriptor) { private static EntityType entityType(String propertyName, EntityPersister entityDescriptor) {
final Type propertyType = entityDescriptor.getPropertyType( propertyName ); final Type propertyType = entityDescriptor.getPropertyType( propertyName );
if ( propertyType.isEntityType() ) { if ( propertyType instanceof EntityType ) {
// the normal case // the normal case
return (EntityType) propertyType; return (EntityType) propertyType;
} }

View File

@ -351,7 +351,7 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn
} }
private static Type getUnderlyingType(Mapping mapping, Type type, int typeIndex) { private static Type getUnderlyingType(Mapping mapping, Type type, int typeIndex) {
if ( type.isComponentType() ) { if ( type instanceof ComponentType ) {
final ComponentType componentType = (ComponentType) type; final ComponentType componentType = (ComponentType) type;
int cols = 0; int cols = 0;
for ( Type subtype : componentType.getSubtypes() ) { for ( Type subtype : componentType.getSubtypes() ) {
@ -363,7 +363,7 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn
} }
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} }
else if ( type.isEntityType() ) { else if ( type instanceof EntityType ) {
final EntityType entityType = (EntityType) type; final EntityType entityType = (EntityType) type;
final Type idType = entityType.getIdentifierOrUniqueKeyType( mapping ); final Type idType = entityType.getIdentifierOrUniqueKeyType( mapping );
return getUnderlyingType( mapping, idType, typeIndex ); return getUnderlyingType( mapping, idType, typeIndex );

View File

@ -30,6 +30,9 @@ import org.hibernate.property.access.spi.Setter;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;
import org.hibernate.generator.Generator; import org.hibernate.generator.Generator;
import org.hibernate.generator.GeneratorCreationContext; import org.hibernate.generator.GeneratorCreationContext;
import org.hibernate.type.AnyType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType; import org.hibernate.type.CompositeType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
import org.hibernate.type.WrapperArrayHandling; import org.hibernate.type.WrapperArrayHandling;
@ -136,10 +139,13 @@ public class Property implements Serializable, MetaAttributable {
public CascadeStyle getCascadeStyle() throws MappingException { public CascadeStyle getCascadeStyle() throws MappingException {
final Type type = value.getType(); final Type type = value.getType();
if ( type.isComponentType() ) { if ( type instanceof AnyType ) {
return getCompositeCascadeStyle( (CompositeType) type, cascade ); return getCascadeStyle( cascade );
} }
else if ( type.isCollectionType() ) { if ( type instanceof ComponentType ) {
return getCompositeCascadeStyle( (ComponentType) type, cascade );
}
else if ( type instanceof CollectionType ) {
final Collection collection = (Collection) value; final Collection collection = (Collection) value;
return getCollectionCascadeStyle( collection.getElement().getType(), cascade ); return getCollectionCascadeStyle( collection.getElement().getType(), cascade );
} }
@ -149,9 +155,15 @@ public class Property implements Serializable, MetaAttributable {
} }
private static CascadeStyle getCompositeCascadeStyle(CompositeType compositeType, String cascade) { private static CascadeStyle getCompositeCascadeStyle(CompositeType compositeType, String cascade) {
if ( compositeType.isAnyType() ) { if ( compositeType instanceof AnyType ) {
return getCascadeStyle( cascade ); return getCascadeStyle( cascade );
} }
else {
return getCompositeCascadeStyle( (ComponentType) compositeType, cascade );
}
}
private static CascadeStyle getCompositeCascadeStyle(ComponentType compositeType, String cascade) {
final int length = compositeType.getSubtypes().length; final int length = compositeType.getSubtypes().length;
for ( int i=0; i<length; i++ ) { for ( int i=0; i<length; i++ ) {
if ( compositeType.getCascadeStyle(i) != CascadeStyles.NONE ) { if ( compositeType.getCascadeStyle(i) != CascadeStyles.NONE ) {
@ -162,9 +174,15 @@ public class Property implements Serializable, MetaAttributable {
} }
private static CascadeStyle getCollectionCascadeStyle(Type elementType, String cascade) { private static CascadeStyle getCollectionCascadeStyle(Type elementType, String cascade) {
return elementType.isComponentType() if ( elementType instanceof AnyType ) {
? getCompositeCascadeStyle( (CompositeType) elementType, cascade ) return getCascadeStyle( cascade );
: getCascadeStyle( cascade ); }
else if ( elementType instanceof ComponentType ) {
return getCompositeCascadeStyle( (ComponentType) elementType, cascade );
}
else {
return getCascadeStyle( cascade );
}
} }
private static CascadeStyle getCascadeStyle(String cascade) { private static CascadeStyle getCascadeStyle(String cascade) {

View File

@ -61,6 +61,9 @@ import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.property.access.internal.PropertyAccessMapImpl; import org.hibernate.property.access.internal.PropertyAccessMapImpl;
import org.hibernate.property.access.spi.Getter; import org.hibernate.property.access.spi.Getter;
import org.hibernate.type.AnyType; import org.hibernate.type.AnyType;
import org.hibernate.type.BasicType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.BasicPluralType; import org.hibernate.type.BasicPluralType;
import org.hibernate.type.EntityType; import org.hibernate.type.EntityType;
import org.hibernate.type.descriptor.java.JavaType; import org.hibernate.type.descriptor.java.JavaType;
@ -461,7 +464,7 @@ public class AttributeFactory {
final org.hibernate.type.Type type = value.getType(); final org.hibernate.type.Type type = value.getType();
LOG.tracef( " Determined type [name=%s, class=%s]", type.getName(), type.getClass().getName() ); LOG.tracef( " Determined type [name=%s, class=%s]", type.getName(), type.getClass().getName() );
if ( type.isAnyType() ) { if ( type instanceof AnyType ) {
return new SingularAttributeMetadataImpl<>( return new SingularAttributeMetadataImpl<>(
propertyMapping, propertyMapping,
attributeContext.getOwnerType(), attributeContext.getOwnerType(),
@ -470,9 +473,7 @@ public class AttributeFactory {
context context
); );
} }
else if ( type.isAssociationType() ) { else if ( type instanceof EntityType ) {
// collection or entity
if ( type.isEntityType() ) {
// entity // entity
return new SingularAttributeMetadataImpl<>( return new SingularAttributeMetadataImpl<>(
propertyMapping, propertyMapping,
@ -482,6 +483,7 @@ public class AttributeFactory {
context context
); );
} }
else if ( type instanceof CollectionType ) {
// collection // collection
if ( value instanceof Collection ) { if ( value instanceof Collection ) {
final Collection collValue = (Collection) value; final Collection collValue = (Collection) value;
@ -519,7 +521,7 @@ public class AttributeFactory {
// ); // );
} }
} }
else if ( propertyMapping.isComposite() ) { else if ( type instanceof ComponentType ) {
// component // component
return new SingularAttributeMetadataImpl<>( return new SingularAttributeMetadataImpl<>(
propertyMapping, propertyMapping,
@ -530,6 +532,7 @@ public class AttributeFactory {
); );
} }
else { else {
assert type instanceof BasicType<?>;
// basic type // basic type
return new SingularAttributeMetadataImpl<>( return new SingularAttributeMetadataImpl<>(
propertyMapping, propertyMapping,
@ -557,14 +560,15 @@ public class AttributeFactory {
private static AttributeClassification elementClassification( private static AttributeClassification elementClassification(
org.hibernate.type.Type elementType, Value elementValue, boolean isManyToMany) { org.hibernate.type.Type elementType, Value elementValue, boolean isManyToMany) {
final AttributeClassification elementClassification; // First, determine the type of the elements and use that to help determine the
if ( elementType.isAnyType() ) { // collection type
if ( elementType instanceof AnyType ) {
return AttributeClassification.ANY; return AttributeClassification.ANY;
} }
else if ( elementValue instanceof Component ) { else if ( elementType instanceof ComponentType ) {
return AttributeClassification.EMBEDDED; return AttributeClassification.EMBEDDED;
} }
else if ( elementType.isAssociationType() ) { else if ( elementType instanceof EntityType ) {
return isManyToMany ? return isManyToMany ?
AttributeClassification.MANY_TO_MANY : AttributeClassification.MANY_TO_MANY :
AttributeClassification.ONE_TO_MANY; AttributeClassification.ONE_TO_MANY;
@ -576,13 +580,7 @@ public class AttributeFactory {
private static AttributeClassification collectionClassification( private static AttributeClassification collectionClassification(
org.hibernate.type.Type elementType, Value elementValue, boolean isManyToMany) { org.hibernate.type.Type elementType, Value elementValue, boolean isManyToMany) {
if ( elementType.isAnyType() ) { if ( elementType instanceof EntityType ) {
return AttributeClassification.ELEMENT_COLLECTION;
}
else if ( elementValue instanceof Component ) {
return AttributeClassification.ELEMENT_COLLECTION;
}
else if ( elementType.isAssociationType() ) {
return isManyToMany ? return isManyToMany ?
AttributeClassification.MANY_TO_MANY : AttributeClassification.MANY_TO_MANY :
AttributeClassification.ONE_TO_MANY; AttributeClassification.ONE_TO_MANY;
@ -593,13 +591,13 @@ public class AttributeFactory {
} }
private static AttributeClassification keyClassification(org.hibernate.type.Type keyType, Value keyValue) { private static AttributeClassification keyClassification(org.hibernate.type.Type keyType, Value keyValue) {
if ( keyType.isAnyType() ) { if ( keyType instanceof AnyType ) {
return AttributeClassification.ANY; return AttributeClassification.ANY;
} }
else if ( keyValue instanceof Component ) { else if ( keyType instanceof ComponentType ) {
return AttributeClassification.EMBEDDED; return AttributeClassification.EMBEDDED;
} }
else if ( keyType.isAssociationType() ) { else if ( keyType instanceof EntityType ) {
return AttributeClassification.MANY_TO_ONE; return AttributeClassification.MANY_TO_ONE;
} }
else { else {

View File

@ -14,6 +14,7 @@ import org.hibernate.mapping.Property;
import org.hibernate.metamodel.AttributeClassification; import org.hibernate.metamodel.AttributeClassification;
import org.hibernate.metamodel.model.domain.ManagedDomainType; import org.hibernate.metamodel.model.domain.ManagedDomainType;
import org.hibernate.metamodel.model.domain.internal.MapMember; import org.hibernate.metamodel.model.domain.internal.MapMember;
import org.hibernate.type.CollectionType;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
@ -87,7 +88,7 @@ public abstract class BaseAttributeMetadata<X, Y> implements AttributeMetadata<X
} }
public boolean isPlural() { public boolean isPlural() {
return propertyMapping.getType().isCollectionType(); return propertyMapping.getType() instanceof CollectionType;
} }
public Property getPropertyMapping() { public Property getPropertyMapping() {

View File

@ -43,6 +43,7 @@ import org.hibernate.sql.results.graph.FetchParent;
import org.hibernate.sql.results.graph.collection.internal.EagerCollectionFetch; import org.hibernate.sql.results.graph.collection.internal.EagerCollectionFetch;
import org.hibernate.sql.results.graph.entity.EntityFetch; import org.hibernate.sql.results.graph.entity.EntityFetch;
import org.hibernate.sql.results.graph.entity.internal.EntityFetchJoinedImpl; import org.hibernate.sql.results.graph.entity.internal.EntityFetchJoinedImpl;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType; import org.hibernate.type.CompositeType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
@ -387,8 +388,8 @@ public abstract class AbstractEntityCollectionPart implements EntityCollectionPa
propertyType = entityBinding.getIdentifierMapper().getType(); propertyType = entityBinding.getIdentifierMapper().getType();
} }
if ( entityBinding.getIdentifierProperty() == null ) { if ( entityBinding.getIdentifierProperty() == null ) {
final CompositeType compositeType; final ComponentType compositeType;
if ( propertyType.isComponentType() && ( compositeType = (CompositeType) propertyType ).isEmbedded() if ( propertyType instanceof ComponentType && ( compositeType = (ComponentType) propertyType ).isEmbedded()
&& compositeType.getPropertyNames().length == 1 ) { && compositeType.getPropertyNames().length == 1 ) {
ToOneAttributeMapping.addPrefixedPropertyPaths( ToOneAttributeMapping.addPrefixedPropertyPaths(
targetKeyPropertyNames, targetKeyPropertyNames,
@ -440,8 +441,8 @@ public abstract class AbstractEntityCollectionPart implements EntityCollectionPa
} }
else { else {
final Type propertyType = entityBinding.getRecursiveProperty( referencedPropertyName ).getType(); final Type propertyType = entityBinding.getRecursiveProperty( referencedPropertyName ).getType();
final CompositeType compositeType; final ComponentType compositeType;
if ( propertyType.isComponentType() && ( compositeType = (CompositeType) propertyType ).isEmbedded() if ( propertyType instanceof ComponentType && ( compositeType = (ComponentType) propertyType ).isEmbedded()
&& compositeType.getPropertyNames().length == 1 ) { && compositeType.getPropertyNames().length == 1 ) {
final Set<String> targetKeyPropertyNames = new HashSet<>( 2 ); final Set<String> targetKeyPropertyNames = new HashSet<>( 2 );
ToOneAttributeMapping.addPrefixedPropertyPaths( ToOneAttributeMapping.addPrefixedPropertyPaths(

View File

@ -16,7 +16,10 @@ import org.hibernate.persister.collection.AbstractCollectionPersister;
import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.sql.results.graph.FetchOptions; import org.hibernate.sql.results.graph.FetchOptions;
import org.hibernate.type.AnyType;
import org.hibernate.type.AssociationType; import org.hibernate.type.AssociationType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.EntityType;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
@ -40,7 +43,7 @@ public final class FetchOptionsHelper {
FetchMode mappingFetchMode, FetchMode mappingFetchMode,
AssociationType type, AssociationType type,
SessionFactoryImplementor sessionFactory) { SessionFactoryImplementor sessionFactory) {
if ( !type.isEntityType() && !type.isCollectionType() ) { if ( !( type instanceof EntityType ) && !( type instanceof CollectionType ) ) {
return FetchStyle.SELECT; return FetchStyle.SELECT;
} }
@ -48,7 +51,7 @@ public final class FetchOptionsHelper {
return FetchStyle.JOIN; return FetchStyle.JOIN;
} }
if ( type.isEntityType() ) { if ( type instanceof EntityType ) {
EntityPersister persister = (EntityPersister) type.getAssociatedJoinable( sessionFactory ); EntityPersister persister = (EntityPersister) type.getAssociatedJoinable( sessionFactory );
if ( persister.isBatchLoadable() ) { if ( persister.isBatchLoadable() ) {
return FetchStyle.BATCH; return FetchStyle.BATCH;
@ -116,11 +119,11 @@ public final class FetchOptionsHelper {
} }
private static boolean isSubsequentSelectDelayed(AssociationType type, SessionFactoryImplementor sessionFactory) { private static boolean isSubsequentSelectDelayed(AssociationType type, SessionFactoryImplementor sessionFactory) {
if ( type.isAnyType() ) { if ( type instanceof AnyType ) {
// we'd need more context here. this is only kept as part of the property state on the owning entity // we'd need more context here. this is only kept as part of the property state on the owning entity
return false; return false;
} }
else if ( type.isEntityType() ) { else if ( type instanceof EntityType ) {
final EntityPersister entityPersister = (EntityPersister) type.getAssociatedJoinable( sessionFactory ); final EntityPersister entityPersister = (EntityPersister) type.getAssociatedJoinable( sessionFactory );
return entityPersister.getEntityMetamodel().isLazy(); return entityPersister.getEntityMetamodel().isLazy();
} }

View File

@ -765,7 +765,7 @@ public class MappingModelCreationHelper {
final ManagedMappingType keyDeclaringType; final ManagedMappingType keyDeclaringType;
final String collectionTableName = collectionDescriptor.getTableName(); final String collectionTableName = collectionDescriptor.getTableName();
if ( collectionDescriptor.getElementType().isEntityType() ) { if ( collectionDescriptor.getElementType() instanceof EntityType ) {
keyDeclaringType = collectionDescriptor.getElementPersister(); keyDeclaringType = collectionDescriptor.getElementPersister();
} }
else { else {

View File

@ -107,6 +107,7 @@ import org.hibernate.sql.results.graph.entity.internal.EntityFetchSelectImpl;
import org.hibernate.sql.results.internal.NullValueAssembler; import org.hibernate.sql.results.internal.NullValueAssembler;
import org.hibernate.sql.results.internal.domain.CircularBiDirectionalFetchImpl; import org.hibernate.sql.results.internal.domain.CircularBiDirectionalFetchImpl;
import org.hibernate.sql.results.internal.domain.CircularFetchImpl; import org.hibernate.sql.results.internal.domain.CircularFetchImpl;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType; import org.hibernate.type.CompositeType;
import org.hibernate.type.EmbeddedComponentType; import org.hibernate.type.EmbeddedComponentType;
import org.hibernate.type.EntityType; import org.hibernate.type.EntityType;
@ -457,8 +458,8 @@ public class ToOneAttributeMapping
propertyType = entityBinding.getIdentifierMapper().getType(); propertyType = entityBinding.getIdentifierMapper().getType();
} }
if ( entityBinding.getIdentifierProperty() == null ) { if ( entityBinding.getIdentifierProperty() == null ) {
final CompositeType compositeType; final ComponentType compositeType;
if ( propertyType.isComponentType() && ( compositeType = (CompositeType) propertyType ).isEmbedded() if ( propertyType instanceof ComponentType && ( compositeType = (ComponentType) propertyType ).isEmbedded()
&& compositeType.getPropertyNames().length == 1 ) { && compositeType.getPropertyNames().length == 1 ) {
this.targetKeyPropertyName = compositeType.getPropertyNames()[0]; this.targetKeyPropertyName = compositeType.getPropertyNames()[0];
addPrefixedPropertyPaths( addPrefixedPropertyPaths(
@ -517,8 +518,8 @@ public class ToOneAttributeMapping
this.targetKeyPropertyNames = targetKeyPropertyNames; this.targetKeyPropertyNames = targetKeyPropertyNames;
} }
else { else {
final CompositeType compositeType; final ComponentType compositeType;
if ( propertyType.isComponentType() && ( compositeType = (CompositeType) propertyType ).isEmbedded() if ( propertyType instanceof ComponentType && ( compositeType = (ComponentType) propertyType ).isEmbedded()
&& compositeType.getPropertyNames().length == 1 ) { && compositeType.getPropertyNames().length == 1 ) {
final Set<String> targetKeyPropertyNames = new HashSet<>( 2 ); final Set<String> targetKeyPropertyNames = new HashSet<>( 2 );
this.targetKeyPropertyName = compositeType.getPropertyNames()[0]; this.targetKeyPropertyName = compositeType.getPropertyNames()[0];
@ -768,7 +769,7 @@ public class ToOneAttributeMapping
if ( prefix != null ) { if ( prefix != null ) {
targetKeyPropertyNames.add( prefix ); targetKeyPropertyNames.add( prefix );
} }
if ( type.isComponentType() ) { if ( type instanceof ComponentType ) {
final CompositeType componentType = (CompositeType) type; final CompositeType componentType = (CompositeType) type;
final String[] propertyNames = componentType.getPropertyNames(); final String[] propertyNames = componentType.getPropertyNames();
final Type[] componentTypeSubtypes = componentType.getSubtypes(); final Type[] componentTypeSubtypes = componentType.getSubtypes();
@ -783,7 +784,7 @@ public class ToOneAttributeMapping
addPrefixedPropertyNames( targetKeyPropertyNames, newPrefix, componentTypeSubtypes[i], factory ); addPrefixedPropertyNames( targetKeyPropertyNames, newPrefix, componentTypeSubtypes[i], factory );
} }
} }
else if ( type.isEntityType() ) { else if ( type instanceof EntityType ) {
final EntityType entityType = (EntityType) type; final EntityType entityType = (EntityType) type;
final Type identifierOrUniqueKeyType = entityType.getIdentifierOrUniqueKeyType( factory ); final Type identifierOrUniqueKeyType = entityType.getIdentifierOrUniqueKeyType( factory );
final String propertyName; final String propertyName;

View File

@ -316,7 +316,7 @@ public class MappingMetamodelImpl extends QueryParameterBindingTypeResolverImpl
); );
collectionPersisterMap.put( model.getRole(), persister ); collectionPersisterMap.put( model.getRole(), persister );
final Type indexType = persister.getIndexType(); final Type indexType = persister.getIndexType();
if ( indexType != null && indexType.isEntityType() && !indexType.isAnyType() ) { if ( indexType instanceof org.hibernate.type.EntityType ) {
final String entityName = ( (org.hibernate.type.EntityType) indexType ).getAssociatedEntityName(); final String entityName = ( (org.hibernate.type.EntityType) indexType ).getAssociatedEntityName();
Set<String> roles = collectionRolesByEntityParticipant.get( entityName ); Set<String> roles = collectionRolesByEntityParticipant.get( entityName );
//noinspection Java8MapApi //noinspection Java8MapApi
@ -327,7 +327,7 @@ public class MappingMetamodelImpl extends QueryParameterBindingTypeResolverImpl
roles.add( persister.getRole() ); roles.add( persister.getRole() );
} }
final Type elementType = persister.getElementType(); final Type elementType = persister.getElementType();
if ( elementType.isEntityType() && !elementType.isAnyType() ) { if ( elementType instanceof org.hibernate.type.EntityType ) {
final String entityName = ( (org.hibernate.type.EntityType) elementType ).getAssociatedEntityName(); final String entityName = ( (org.hibernate.type.EntityType) elementType ).getAssociatedEntityName();
Set<String> roles = collectionRolesByEntityParticipant.get( entityName ); Set<String> roles = collectionRolesByEntityParticipant.get( entityName );
//noinspection Java8MapApi //noinspection Java8MapApi

View File

@ -134,6 +134,7 @@ import org.hibernate.sql.results.internal.SqlSelectionImpl;
import org.hibernate.type.AnyType; import org.hibernate.type.AnyType;
import org.hibernate.type.BasicType; import org.hibernate.type.BasicType;
import org.hibernate.type.CollectionType; import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType; import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType; import org.hibernate.type.EntityType;
import org.hibernate.type.MetaType; import org.hibernate.type.MetaType;
@ -301,7 +302,7 @@ public abstract class AbstractCollectionPersister
/* /*
* Add the predicate on the role in the WHERE clause before creating the SQL queries. * Add the predicate on the role in the WHERE clause before creating the SQL queries.
*/ */
if ( mappedByProperty != null && elementType.isEntityType() ) { if ( mappedByProperty != null && elementType instanceof EntityType ) {
final String entityName = ( (EntityType) elementType ).getAssociatedEntityName(); final String entityName = ( (EntityType) elementType ).getAssociatedEntityName();
final PersistentClass persistentClass = creationContext.getBootModel().getEntityBinding( entityName ); final PersistentClass persistentClass = creationContext.getBootModel().getEntityBinding( entityName );
final Property property = persistentClass.getRecursiveProperty( mappedByProperty ); final Property property = persistentClass.getRecursiveProperty( mappedByProperty );
@ -367,7 +368,7 @@ public abstract class AbstractCollectionPersister
// ELEMENT // ELEMENT
if ( elementType.isEntityType() ) { if ( elementType instanceof EntityType ) {
String entityName = ( (EntityType) elementType ).getAssociatedEntityName(); String entityName = ( (EntityType) elementType ).getAssociatedEntityName();
elementPersister = creationContext.getDomainModel().getEntityDescriptor( entityName ); elementPersister = creationContext.getDomainModel().getEntityDescriptor( entityName );
// NativeSQL: collect element column and auto-aliases // NativeSQL: collect element column and auto-aliases
@ -418,7 +419,7 @@ public abstract class AbstractCollectionPersister
creationContext.getFunctionRegistry() creationContext.getFunctionRegistry()
); );
elementColumnIsGettable[j] = true; elementColumnIsGettable[j] = true;
if ( elementType.isComponentType() ) { if ( elementType instanceof ComponentType || elementType instanceof AnyType ) {
// Implements desired behavior specifically for @ElementCollection mappings. // Implements desired behavior specifically for @ElementCollection mappings.
elementColumnIsSettable[j] = columnInsertability[j]; elementColumnIsSettable[j] = columnInsertability[j];
} }
@ -1369,7 +1370,7 @@ public abstract class AbstractCollectionPersister
collectionPropertyColumnAliases.put( aliasName, columnAliases ); collectionPropertyColumnAliases.put( aliasName, columnAliases );
//TODO: this code is almost certainly obsolete and can be removed //TODO: this code is almost certainly obsolete and can be removed
if ( type.isComponentType() ) { if ( type instanceof ComponentType || type instanceof AnyType ) {
CompositeType ct = (CompositeType) type; CompositeType ct = (CompositeType) type;
String[] propertyNames = ct.getPropertyNames(); String[] propertyNames = ct.getPropertyNames();
for ( int i = 0; i < propertyNames.length; i++ ) { for ( int i = 0; i < propertyNames.length; i++ ) {

View File

@ -59,6 +59,7 @@ import org.hibernate.sql.model.ast.builder.TableInsertBuilderStandard;
import org.hibernate.sql.model.ast.builder.TableUpdateBuilderStandard; import org.hibernate.sql.model.ast.builder.TableUpdateBuilderStandard;
import org.hibernate.sql.model.internal.TableUpdateStandard; import org.hibernate.sql.model.internal.TableUpdateStandard;
import org.hibernate.sql.model.jdbc.JdbcMutationOperation; import org.hibernate.sql.model.jdbc.JdbcMutationOperation;
import org.hibernate.type.EntityType;
import static org.hibernate.internal.util.collections.CollectionHelper.arrayList; import static org.hibernate.internal.util.collections.CollectionHelper.arrayList;
import static org.hibernate.sql.model.ModelMutationLogging.MODEL_MUTATION_LOGGER; import static org.hibernate.sql.model.ModelMutationLogging.MODEL_MUTATION_LOGGER;
@ -751,7 +752,7 @@ public class BasicCollectionPersister extends AbstractCollectionPersister {
@Override @Override
public boolean isManyToMany() { public boolean isManyToMany() {
return elementType.isEntityType(); //instanceof AssociationType; return elementType instanceof EntityType; //instanceof AssociationType;
} }
@Override @Override

View File

@ -279,6 +279,7 @@ import org.hibernate.type.AnyType;
import org.hibernate.type.AssociationType; import org.hibernate.type.AssociationType;
import org.hibernate.type.BasicType; import org.hibernate.type.BasicType;
import org.hibernate.type.CollectionType; import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType; import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType; import org.hibernate.type.EntityType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
@ -896,7 +897,7 @@ public abstract class AbstractEntityPersister
// 2) have no associations. // 2) have no associations.
// Eventually we want to be a little more lenient with associations. // Eventually we want to be a little more lenient with associations.
for ( Type type : getSubclassPropertyTypeClosure() ) { for ( Type type : getSubclassPropertyTypeClosure() ) {
if ( type.isAssociationType() ) { if ( type instanceof AnyType || type instanceof CollectionType || type instanceof EntityType ) {
return false; return false;
} }
} }
@ -1432,7 +1433,7 @@ public abstract class AbstractEntityPersister
if ( hasCollections() ) { if ( hasCollections() ) {
final Type type = getPropertyType( fieldName ); final Type type = getPropertyType( fieldName );
if ( type.isCollectionType() ) { if ( type instanceof CollectionType ) {
// we have a condition where a collection attribute is being access via enhancement: // we have a condition where a collection attribute is being access via enhancement:
// we can circumvent all the rest and just return the PersistentCollection // we can circumvent all the rest and just return the PersistentCollection
final CollectionType collectionType = (CollectionType) type; final CollectionType collectionType = (CollectionType) type;
@ -2150,7 +2151,7 @@ public abstract class AbstractEntityPersister
// // performance op to avoid the array search // // performance op to avoid the array search
// return 0; // return 0;
// } // }
// else if ( type.isCollectionType() ) { // else if ( type instanceof CollectionType ) {
// // properly handle property-ref-based associations // // properly handle property-ref-based associations
// rootPropertyName = assocType.getLHSPropertyName(); // rootPropertyName = assocType.getLHSPropertyName();
// } // }
@ -6101,9 +6102,9 @@ public abstract class AbstractEntityPersister
} }
// aliases for composite-id's // aliases for composite-id's
if ( getIdentifierType().isComponentType() ) { if ( getIdentifierType() instanceof ComponentType ) {
// Fetch embedded identifiers property names from the "virtual" identifier component // Fetch embedded identifiers property names from the "virtual" identifier component
final CompositeType componentId = (CompositeType) getIdentifierType(); final ComponentType componentId = (ComponentType) getIdentifierType();
final String[] idPropertyNames = componentId.getPropertyNames(); final String[] idPropertyNames = componentId.getPropertyNames();
final String[] idAliases = getIdentifierAliases(); final String[] idAliases = getIdentifierAliases();

View File

@ -26,6 +26,7 @@ import org.hibernate.mapping.PersistentClass;
import org.hibernate.type.AnyType; import org.hibernate.type.AnyType;
import org.hibernate.type.AssociationType; import org.hibernate.type.AssociationType;
import org.hibernate.type.CollectionType; import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType; import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType; import org.hibernate.type.EntityType;
import org.hibernate.type.ManyToOneType; import org.hibernate.type.ManyToOneType;
@ -249,7 +250,7 @@ class EntityPropertyMapping {
); );
} }
if ( type.isAssociationType() ) { if ( type instanceof AnyType || type instanceof CollectionType || type instanceof EntityType ) {
AssociationType actype = (AssociationType) type; AssociationType actype = (AssociationType) type;
if ( actype.useLHSPrimaryKey() ) { if ( actype.useLHSPrimaryKey() ) {
columns = getIdentifierColumnNames(); columns = getIdentifierColumnNames();
@ -275,8 +276,20 @@ class EntityPropertyMapping {
addPropertyPath( path, type, columns, columnReaders, columnReaderTemplates, factory ); addPropertyPath( path, type, columns, columnReaders, columnReaderTemplates, factory );
} }
if ( type.isComponentType() ) { if ( type instanceof AnyType ) {
CompositeType actype = (CompositeType) type; AnyType actype = (AnyType) type;
initComponentPropertyPaths(
path,
actype,
columns,
columnReaders,
columnReaderTemplates,
formulaTemplates,
factory
);
}
else if ( type instanceof ComponentType ) {
ComponentType actype = (ComponentType) type;
initComponentPropertyPaths( initComponentPropertyPaths(
path, path,
actype, actype,
@ -298,7 +311,7 @@ class EntityPropertyMapping {
); );
} }
} }
else if ( type.isEntityType() ) { else if ( type instanceof EntityType ) {
initIdentifierPropertyPaths( initIdentifierPropertyPaths(
path, path,
(EntityType) type, (EntityType) type,

View File

@ -405,7 +405,7 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext {
String entitySuffix) { String entitySuffix) {
final CollectionPersister collectionPersister = collectionReturn.getPluralAttribute().getCollectionDescriptor(); final CollectionPersister collectionPersister = collectionReturn.getPluralAttribute().getCollectionDescriptor();
final String[] elementColumnAliases; final String[] elementColumnAliases;
if ( collectionPersister.getElementType().isEntityType() ) { if ( collectionPersister.getElementType() instanceof EntityType ) {
final EntityPersister elementPersister = collectionPersister.getElementPersister(); final EntityPersister elementPersister = collectionPersister.getElementPersister();
final String[] propertyNames = elementPersister.getPropertyNames(); final String[] propertyNames = elementPersister.getPropertyNames();
final String[] identifierAliases = elementPersister.getIdentifierAliases( entitySuffix ); final String[] identifierAliases = elementPersister.getIdentifierAliases( entitySuffix );
@ -558,13 +558,13 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext {
EntityPersister ownerPersister = alias2Persister.get( ownerAlias ); EntityPersister ownerPersister = alias2Persister.get( ownerAlias );
Type returnType = ownerPersister.getPropertyType( fetchReturn.getFetchableName() ); Type returnType = ownerPersister.getPropertyType( fetchReturn.getFetchableName() );
if ( returnType.isCollectionType() ) { if ( returnType instanceof CollectionType ) {
String role = ownerPersister.getEntityName() + '.' + fetchReturn.getFetchableName(); String role = ownerPersister.getEntityName() + '.' + fetchReturn.getFetchableName();
Map<String, String[]> propertyResultsMap = Collections.emptyMap();//fetchReturn.getPropertyResultsMap() Map<String, String[]> propertyResultsMap = Collections.emptyMap();//fetchReturn.getPropertyResultsMap()
addCollection( role, alias, propertyResultsMap ); addCollection( role, alias, propertyResultsMap );
// collectionOwnerAliases.add( ownerAlias ); // collectionOwnerAliases.add( ownerAlias );
} }
else if ( returnType.isEntityType() ) { else if ( returnType instanceof EntityType ) {
EntityType eType = ( EntityType ) returnType; EntityType eType = ( EntityType ) returnType;
String returnEntityName = eType.getAssociatedEntityName(); String returnEntityName = eType.getAssociatedEntityName();
EntityPersister persister = getSQLLoadable( returnEntityName ); EntityPersister persister = getSQLLoadable( returnEntityName );
@ -624,7 +624,7 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext {
// } // }
// for ( CollectionPersister persister : alias2CollectionPersister.values() ) { // for ( CollectionPersister persister : alias2CollectionPersister.values() ) {
// final Type elementType = persister.getElementType(); // final Type elementType = persister.getElementType();
// if ( elementType.isEntityType() && ! elementType.isAnyType() ) { // if ( elementType instanceof EntityType && ! elementType instanceof AnyType ) {
// final Joinable joinable = ( (EntityType) elementType ).getAssociatedJoinable( factory ); // final Joinable joinable = ( (EntityType) elementType ).getAssociatedJoinable( factory );
// Collections.addAll( spaces, (String[]) ( (EntityPersister) joinable ).getQuerySpaces() ); // Collections.addAll( spaces, (String[]) ( (EntityPersister) joinable ).getQuerySpaces() );
// } // }

View File

@ -48,6 +48,7 @@ import org.hibernate.sql.results.jdbc.spi.JdbcValuesMappingResolution;
import org.hibernate.sql.results.spi.RowReader; import org.hibernate.sql.results.spi.RowReader;
import org.hibernate.sql.results.spi.RowTransformer; import org.hibernate.sql.results.spi.RowTransformer;
import org.hibernate.stat.spi.StatisticsImplementor; import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.type.EntityType;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
@ -203,7 +204,7 @@ public class ResultsHelper {
); );
boolean isPutFromLoad = true; boolean isPutFromLoad = true;
if ( collectionDescriptor.getElementType().isAssociationType() ) { if ( collectionDescriptor.getElementType() instanceof EntityType ) {
final EntityPersister entityPersister = collectionDescriptor.getElementPersister(); final EntityPersister entityPersister = collectionDescriptor.getElementPersister();
for ( Object id : entry.getState() ) { for ( Object id : entry.getState() ) {
if ( persistenceContext.wasInsertedDuringTransaction( entityPersister, id ) ) { if ( persistenceContext.wasInsertedDuringTransaction( entityPersister, id ) ) {

View File

@ -20,8 +20,12 @@ import org.hibernate.tuple.entity.EntityBasedAssociationAttribute;
import org.hibernate.tuple.entity.EntityBasedBasicAttribute; import org.hibernate.tuple.entity.EntityBasedBasicAttribute;
import org.hibernate.tuple.entity.EntityBasedCompositionAttribute; import org.hibernate.tuple.entity.EntityBasedCompositionAttribute;
import org.hibernate.tuple.entity.VersionProperty; import org.hibernate.tuple.entity.VersionProperty;
import org.hibernate.type.AnyType;
import org.hibernate.type.AssociationType; import org.hibernate.type.AssociationType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType; import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
/** /**
@ -218,22 +222,19 @@ public final class PropertyFactory {
} }
private static NonIdentifierAttributeNature decode(Type type) { private static NonIdentifierAttributeNature decode(Type type) {
if ( type.isAssociationType() ) { if ( type instanceof CollectionType ) {
return NonIdentifierAttributeNature.COLLECTION;
if ( type.isComponentType() ) { }
// an any type is both an association and a composite... else if ( type instanceof EntityType ) {
return NonIdentifierAttributeNature.ENTITY;
}
else if ( type instanceof AnyType ) {
return NonIdentifierAttributeNature.ANY; return NonIdentifierAttributeNature.ANY;
} }
else if ( type instanceof ComponentType ) {
return type.isCollectionType()
? NonIdentifierAttributeNature.COLLECTION
: NonIdentifierAttributeNature.ENTITY;
}
else {
if ( type.isComponentType() ) {
return NonIdentifierAttributeNature.COMPOSITE; return NonIdentifierAttributeNature.COMPOSITE;
} }
else {
return NonIdentifierAttributeNature.BASIC; return NonIdentifierAttributeNature.BASIC;
} }
} }

View File

@ -577,7 +577,7 @@ public class EntityMetamodel implements Serializable {
} }
private static boolean indicatesCollection(Type type) { private static boolean indicatesCollection(Type type) {
if ( type.isCollectionType() ) { if ( type instanceof CollectionType ) {
return true; return true;
} }
else if ( type.isComponentType() ) { else if ( type.isComponentType() ) {
@ -592,7 +592,7 @@ public class EntityMetamodel implements Serializable {
} }
private static boolean indicatesOwnedCollection(Type type, MetadataImplementor metadata) { private static boolean indicatesOwnedCollection(Type type, MetadataImplementor metadata) {
if ( type.isCollectionType() ) { if ( type instanceof CollectionType ) {
final CollectionType collectionType = (CollectionType) type; final CollectionType collectionType = (CollectionType) type;
return !metadata.getCollectionBinding( collectionType.getRole() ).isInverse(); return !metadata.getCollectionBinding( collectionType.getRole() ).isInverse();
} }

View File

@ -119,7 +119,8 @@ public abstract class AbstractType implements Type {
} }
private boolean needsReplacement(ForeignKeyDirection foreignKeyDirection) { private boolean needsReplacement(ForeignKeyDirection foreignKeyDirection) {
if ( isAssociationType() ) { // Collection and OneToOne are the only associations that could be TO_PARENT
if ( this instanceof CollectionType || this instanceof OneToOneType ) {
final AssociationType associationType = (AssociationType) this; final AssociationType associationType = (AssociationType) this;
return associationType.getForeignKeyDirection() == foreignKeyDirection; return associationType.getForeignKeyDirection() == foreignKeyDirection;
} }

View File

@ -468,7 +468,7 @@ public abstract class CollectionType extends AbstractType implements Association
CollectionPersister collectionPersister = factory.getRuntimeMetamodels().getMappingMetamodel().getCollectionDescriptor( role ); CollectionPersister collectionPersister = factory.getRuntimeMetamodels().getMappingMetamodel().getCollectionDescriptor( role );
if ( !collectionPersister.getElementType().isEntityType() ) { if ( !( collectionPersister.getElementType() instanceof EntityType ) ) {
throw new MappingException( throw new MappingException(
"collection was not an association: " + "collection was not an association: " +
collectionPersister.getRole() collectionPersister.getRole()

View File

@ -496,7 +496,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
// we need to dig a little deeper, as that property might also be // we need to dig a little deeper, as that property might also be
// an entity type, in which case we need to resolve its identifier // an entity type, in which case we need to resolve its identifier
final Type type = entityPersister.getPropertyType( uniqueKeyPropertyName ); final Type type = entityPersister.getPropertyType( uniqueKeyPropertyName );
if ( type.isEntityType() ) { if ( type instanceof EntityType ) {
return ( (EntityType) type ).getIdentifier( propertyValue, session ); return ( (EntityType) type ).getIdentifier( propertyValue, session );
} }
else { else {
@ -521,7 +521,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
// we need to dig a little deeper, as that property might also be // we need to dig a little deeper, as that property might also be
// an entity type, in which case we need to resolve its identifier // an entity type, in which case we need to resolve its identifier
final Type type = entityPersister.getPropertyType( uniqueKeyPropertyName ); final Type type = entityPersister.getPropertyType( uniqueKeyPropertyName );
if ( type.isEntityType() ) { if ( type instanceof EntityType ) {
return ( (EntityType) type ).getIdentifier( propertyValue, sessionFactory ); return ( (EntityType) type ).getIdentifier( propertyValue, sessionFactory );
} }
else { else {
@ -646,7 +646,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
} }
else { else {
final Type type = factory.getReferencedPropertyType( getAssociatedEntityName(), uniqueKeyPropertyName ); final Type type = factory.getReferencedPropertyType( getAssociatedEntityName(), uniqueKeyPropertyName );
if ( type.isEntityType() ) { if ( type instanceof EntityType ) {
return ( (EntityType) type ).getIdentifierOrUniqueKeyType( factory ); return ( (EntityType) type ).getIdentifierOrUniqueKeyType( factory );
} }
else { else {

View File

@ -193,12 +193,12 @@ public class TypeHelper {
final Type type = types[i]; final Type type = types[i];
// AnyType is both a CompositeType and an AssociationType // AnyType is both a CompositeType and an AssociationType
// but here we want to treat it as an association // but here we want to treat it as an association
if ( type.isAssociationType() ) { if ( type instanceof EntityType || type instanceof CollectionType || type instanceof AnyType ) {
copied[i] = types[i].replace( currentOriginal, target[i], session, owner, copyCache, foreignKeyDirection ); copied[i] = types[i].replace( currentOriginal, target[i], session, owner, copyCache, foreignKeyDirection );
} }
else { else {
if ( type.isComponentType() ) { if ( type instanceof ComponentType ) {
final CompositeType compositeType = (CompositeType) type; final ComponentType compositeType = (ComponentType) type;
if ( target[i] != null ) { if ( target[i] != null ) {
// need to extract the component values and check for subtype replacements... // need to extract the component values and check for subtype replacements...
final Object[] objects = replaceCompositeAssociations( final Object[] objects = replaceCompositeAssociations(
@ -224,7 +224,7 @@ public class TypeHelper {
Map<Object, Object> copyCache, Map<Object, Object> copyCache,
ForeignKeyDirection foreignKeyDirection, ForeignKeyDirection foreignKeyDirection,
Object target, Object currentOriginal, Object target, Object currentOriginal,
CompositeType compositeType) { ComponentType compositeType) {
final Type[] subtypes = compositeType.getSubtypes(); final Type[] subtypes = compositeType.getSubtypes();
return replaceAssociations( return replaceAssociations(
currentOriginal == null currentOriginal == null

View File

@ -200,7 +200,7 @@ public class BasicCollectionMapper<T extends Collection> extends AbstractCollect
// Currently the tuple is { owner_id, entity_id, rev } and so having this special // Currently the tuple is { owner_id, entity_id, rev } and so having this special
// treatment is critical to avoid HHH-13080. // treatment is critical to avoid HHH-13080.
// //
if ( elementType.isEntityType() && !revisionTypeInId ) { if ( elementType instanceof EntityType && !revisionTypeInId ) {
// This is a short-circuit to check for reference equality only. // This is a short-circuit to check for reference equality only.
// There is no need to delegate to the identifier if the objects are reference equal. // There is no need to delegate to the identifier if the objects are reference equal.

View File

@ -433,7 +433,7 @@ public class ValidityAuditStrategy implements AuditStrategy {
final Type propertyType = session.getSessionFactory() final Type propertyType = session.getSessionFactory()
.getMappingMetamodel() .getMappingMetamodel()
.getEntityDescriptor( entityName ).getPropertyType( propertyName ); .getEntityDescriptor( entityName ).getPropertyType( propertyName );
if ( propertyType.isCollectionType() ) { if ( propertyType instanceof CollectionType ) {
final CollectionType collectionType = (CollectionType) propertyType; final CollectionType collectionType = (CollectionType) propertyType;
final Type collectionElementType = collectionType.getElementType( session.getSessionFactory() ); final Type collectionElementType = collectionType.getElementType( session.getSessionFactory() );
if ( collectionElementType instanceof ComponentType ) { if ( collectionElementType instanceof ComponentType ) {

View File

@ -11,6 +11,7 @@ import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.entity.Joinable; import org.hibernate.persister.entity.Joinable;
import org.hibernate.type.CollectionType; import org.hibernate.type.CollectionType;
import org.hibernate.type.EntityType;
import org.hibernate.type.ListType; import org.hibernate.type.ListType;
import org.hibernate.type.MapType; import org.hibernate.type.MapType;
import org.hibernate.type.Type; import org.hibernate.type.Type;
@ -96,7 +97,7 @@ public abstract class MockCollectionPersister implements CollectionPersister, Jo
@Override @Override
public EntityPersister getElementPersister() { public EntityPersister getElementPersister() {
if (elementType.isEntityType()) { if (elementType instanceof EntityType ) {
return factory.getMetamodel() return factory.getMetamodel()
.entityPersister(elementType.getName()); .entityPersister(elementType.getName());
} }
@ -112,7 +113,7 @@ public abstract class MockCollectionPersister implements CollectionPersister, Jo
@Override @Override
public boolean isOneToMany() { public boolean isOneToMany() {
return elementType.isEntityType(); return elementType instanceof EntityType;
} }
@Override @Override