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

View File

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

View File

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

View File

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

View File

@ -16,7 +16,8 @@ import org.hibernate.engine.spi.SelfDirtinessTracker;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.persister.entity.EntityPersister;
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.Type;
@ -106,21 +107,21 @@ public final class ForeignKeys {
if ( value == null ) {
return null;
}
else if ( type.isEntityType() ) {
else if ( type instanceof EntityType ) {
return nullifyEntityType( value, propertyName, (EntityType) type );
}
else if ( type.isAnyType() ) {
else if ( type instanceof AnyType ) {
return isNullifiable( null, value) ? null : value;
}
else if ( type.isComponentType() ) {
return nullifyCompositeType( value, propertyName, (CompositeType) type );
else if ( type instanceof ComponentType ) {
return nullifyCompositeType( value, propertyName, (ComponentType) type );
}
else {
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 Type[] subtypes = compositeType.getSubtypes();
final String[] subPropertyNames = compositeType.getPropertyNames();
@ -194,7 +195,7 @@ public final class ForeignKeys {
// more than just initializing the associated entity.
return isDelete
&& value == UNFETCHED_PROPERTY
&& type.isEntityType()
&& type instanceof EntityType
&& !session.getPersistenceContextInternal().isNullifiableEntityKeysEmpty();
}
@ -432,7 +433,7 @@ public final class ForeignKeys {
if ( value == null ) {
// do nothing
}
else if ( type.isEntityType() ) {
else if ( type instanceof EntityType ) {
final EntityType entityType = (EntityType) type;
if ( !isNullable
&& !entityType.isOneToOne()
@ -440,13 +441,13 @@ public final class ForeignKeys {
nonNullableTransientEntities.add( propertyName, value );
}
}
else if ( type.isAnyType() ) {
else if ( type instanceof AnyType ) {
if ( !isNullable && nullifier.isNullifiable( null, value ) ) {
nonNullableTransientEntities.add( propertyName, value );
}
}
else if ( type.isComponentType() ) {
final CompositeType compositeType = (CompositeType) type;
else if ( type instanceof ComponentType ) {
final ComponentType compositeType = (ComponentType) type;
final boolean[] subValueNullability = compositeType.getPropertyNullability();
if ( subValueNullability != null ) {
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.persister.entity.EntityPersister;
import org.hibernate.generator.Generator;
import org.hibernate.type.AnyType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;
@ -144,16 +146,19 @@ public final class Nullability {
* @throws HibernateException error while getting subcomponent values
*/
private String checkSubElementsNullability(Type propertyType, Object value) throws HibernateException {
if ( propertyType.isComponentType() ) {
return checkComponentNullability( value, (CompositeType) propertyType );
if ( propertyType instanceof AnyType ) {
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
final CollectionType collectionType = (CollectionType) propertyType;
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
final CompositeType componentType = (CompositeType) collectionElementType;
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
if ( compositeType.isAnyType() ) {
if ( compositeType instanceof AnyType ) {
return null;
}

View File

@ -14,6 +14,7 @@ import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.BagType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.Type;
import org.checkerframework.checker.nullness.qual.Nullable;
@ -72,7 +73,7 @@ public class FetchProfile {
final String role = association.getRole();
final Type associationType =
association.getOwner().getPropertyType( association.getAssociationPath() );
if ( associationType.isCollectionType() ) {
if ( associationType instanceof CollectionType ) {
LOG.tracev( "Handling request to add collection fetch [{0}]", role );
// 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.proxy.LazyInitializer;
import org.hibernate.type.CollectionType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.EntityType;
import org.hibernate.type.ForeignKeyDirection;
import org.hibernate.type.Type;
@ -1167,7 +1167,10 @@ public class ActionQueue {
}
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 InsertInfo insertInfo = insertInfosByEntity.get( value );
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;
final PluralAttributeMapping pluralAttributeMapping = insertAction.getSession()
.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.
final CompositeType compositeType = (CompositeType) type;
ComponentType compositeType = (ComponentType) type;
final SharedSessionContractImplementor session = insertAction.getSession();
final Object[] componentValues = compositeType.getPropertyValues( value, session );
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.event.spi.EventSource;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.AnyType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
@ -87,15 +89,18 @@ public abstract class AbstractVisitor {
*/
final Object processValue(Object value, Type type) throws HibernateException {
if ( type.isCollectionType() ) {
if ( type instanceof CollectionType ) {
//even process null collections
return processCollection( value, (CollectionType) type );
}
else if ( type.isEntityType() ) {
else if ( type instanceof EntityType ) {
return processEntity( value, (EntityType) type );
}
else if ( type.isComponentType() ) {
return processComponent( value, (CompositeType) type );
else if ( type instanceof ComponentType ) {
return processComponent( value, (ComponentType) type );
}
else if ( type instanceof AnyType ) {
return processComponent( value, (AnyType) type );
}
else {
return null;

View File

@ -47,6 +47,7 @@ import org.hibernate.property.access.internal.PropertyAccessStrategyBackRefImpl;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;
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) {
final MappingMetamodelImplementor mappingMetamodel = session.getFactory().getMappingMetamodel();
final ActionQueue actionQueue = session.getActionQueue();
if ( type.isCollectionType() ) {
if ( type instanceof CollectionType ) {
final String role = ( (CollectionType) type ).getRole();
final CollectionPersister persister = mappingMetamodel.getCollectionDescriptor(role);
if ( !persister.isInverse() && !skipRemoval( session, persister, key ) ) {
actionQueue.addAction( new CollectionRemoveAction( persister, key, session ) );
}
}
else if ( type.isComponentType() ) {
final Type[] subtypes = ( (CompositeType) type ).getSubtypes();
else if ( type instanceof ComponentType ) {
final Type[] subtypes = ( (ComponentType) type ).getSubtypes();
for ( Type subtype : subtypes ) {
deleteOwnedCollections( subtype, key, session );
}
@ -459,7 +460,7 @@ public class DefaultDeleteEventListener implements DeleteEventListener, Callback
final String[] propertyNames = persister.getPropertyNames();
final BytecodeEnhancementMetadata enhancementMetadata = persister.getBytecodeEnhancementMetadata();
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 CollectionPersister collectionDescriptor = persister.getFactory().getMappingMetamodel()
.getCollectionDescriptor( collectionType.getRole() );

View File

@ -41,7 +41,9 @@ import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.type.AnyType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
import org.hibernate.type.ForeignKeyDirection;
@ -165,14 +167,14 @@ public class DefaultMergeEventListener
originalId = persister.getIdentifier( entity, source );
if ( originalId != null ) {
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
generating the EntityKey will cause a NPE when trying to get the hashcode of the null id
*/
copiedId = copyCompositeTypeId(
originalId,
(CompositeType) persister.getIdentifierType(),
(ComponentType) persister.getIdentifierType(),
source,
copiedAlready
);
@ -250,7 +252,7 @@ public class DefaultMergeEventListener
final Object[] copyValues = compositeType.getPropertyValues( idCopy );
for ( int i = 0; i < subtypes.length; 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
final Object o = mergeContext.get( propertyValues[i] );
if ( o != null ) {
@ -260,8 +262,11 @@ public class DefaultMergeEventListener
copyValues[i] = subtype.deepCopy( propertyValues[i], sessionFactory );
}
}
else if ( subtype.isComponentType() ) {
copyValues[i] = copyCompositeTypeId( propertyValues[i], (CompositeType) subtype, session, mergeContext );
else if ( subtype instanceof AnyType ) {
copyValues[i] = copyCompositeTypeId( propertyValues[i], (AnyType) subtype, session, mergeContext );
}
else if ( subtype instanceof ComponentType ) {
copyValues[i] = copyCompositeTypeId( propertyValues[i], (ComponentType) subtype, session, mergeContext );
}
else {
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.LazyInitializer;
import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;
@ -315,7 +316,7 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
final SessionFactoryImplementor factory = source.getFactory();
final MappingMetamodelImplementor metamodel = factory.getRuntimeMetamodels().getMappingMetamodel();
for ( Type type : types ) {
if ( type.isCollectionType() ) {
if ( type instanceof CollectionType ) {
final String role = ((CollectionType) type).getRole();
final CollectionPersister collectionPersister = metamodel.getCollectionDescriptor( role );
if ( collectionPersister.hasCache() ) {
@ -331,8 +332,9 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
actionQueue.registerProcess( (success, session) -> cache.unlockItem( session, ck, lock ) );
}
}
else if ( type.isComponentType() ) {
final CompositeType compositeType = (CompositeType) type;
else if ( type instanceof ComponentType ) {
// Only components can contain collections
ComponentType compositeType = (ComponentType) type;
evictCachedCollections( compositeType.getSubtypes(), id, source );
}
}

View File

@ -173,7 +173,7 @@ public final class IdentifierGeneratorHelper {
private static EntityType entityType(String propertyName, EntityPersister entityDescriptor) {
final Type propertyType = entityDescriptor.getPropertyType( propertyName );
if ( propertyType.isEntityType() ) {
if ( propertyType instanceof EntityType ) {
// the normal case
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) {
if ( type.isComponentType() ) {
if ( type instanceof ComponentType ) {
final ComponentType componentType = (ComponentType) type;
int cols = 0;
for ( Type subtype : componentType.getSubtypes() ) {
@ -363,7 +363,7 @@ public class Column implements Selectable, Serializable, Cloneable, ColumnTypeIn
}
throw new IndexOutOfBoundsException();
}
else if ( type.isEntityType() ) {
else if ( type instanceof EntityType ) {
final EntityType entityType = (EntityType) type;
final Type idType = entityType.getIdentifierOrUniqueKeyType( mapping );
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.generator.Generator;
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.Type;
import org.hibernate.type.WrapperArrayHandling;
@ -136,10 +139,13 @@ public class Property implements Serializable, MetaAttributable {
public CascadeStyle getCascadeStyle() throws MappingException {
final Type type = value.getType();
if ( type.isComponentType() ) {
return getCompositeCascadeStyle( (CompositeType) type, cascade );
if ( type instanceof AnyType ) {
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;
return getCollectionCascadeStyle( collection.getElement().getType(), cascade );
}
@ -149,9 +155,15 @@ public class Property implements Serializable, MetaAttributable {
}
private static CascadeStyle getCompositeCascadeStyle(CompositeType compositeType, String cascade) {
if ( compositeType.isAnyType() ) {
if ( compositeType instanceof AnyType ) {
return getCascadeStyle( cascade );
}
else {
return getCompositeCascadeStyle( (ComponentType) compositeType, cascade );
}
}
private static CascadeStyle getCompositeCascadeStyle(ComponentType compositeType, String cascade) {
final int length = compositeType.getSubtypes().length;
for ( int i=0; i<length; i++ ) {
if ( compositeType.getCascadeStyle(i) != CascadeStyles.NONE ) {
@ -162,9 +174,15 @@ public class Property implements Serializable, MetaAttributable {
}
private static CascadeStyle getCollectionCascadeStyle(Type elementType, String cascade) {
return elementType.isComponentType()
? getCompositeCascadeStyle( (CompositeType) elementType, cascade )
: getCascadeStyle( cascade );
if ( elementType instanceof AnyType ) {
return getCascadeStyle( cascade );
}
else if ( elementType instanceof ComponentType ) {
return getCompositeCascadeStyle( (ComponentType) elementType, cascade );
}
else {
return getCascadeStyle( 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.spi.Getter;
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.EntityType;
import org.hibernate.type.descriptor.java.JavaType;
@ -461,7 +464,7 @@ public class AttributeFactory {
final org.hibernate.type.Type type = value.getType();
LOG.tracef( " Determined type [name=%s, class=%s]", type.getName(), type.getClass().getName() );
if ( type.isAnyType() ) {
if ( type instanceof AnyType ) {
return new SingularAttributeMetadataImpl<>(
propertyMapping,
attributeContext.getOwnerType(),
@ -470,9 +473,7 @@ public class AttributeFactory {
context
);
}
else if ( type.isAssociationType() ) {
// collection or entity
if ( type.isEntityType() ) {
else if ( type instanceof EntityType ) {
// entity
return new SingularAttributeMetadataImpl<>(
propertyMapping,
@ -482,6 +483,7 @@ public class AttributeFactory {
context
);
}
else if ( type instanceof CollectionType ) {
// collection
if ( value instanceof Collection ) {
final Collection collValue = (Collection) value;
@ -519,7 +521,7 @@ public class AttributeFactory {
// );
}
}
else if ( propertyMapping.isComposite() ) {
else if ( type instanceof ComponentType ) {
// component
return new SingularAttributeMetadataImpl<>(
propertyMapping,
@ -530,6 +532,7 @@ public class AttributeFactory {
);
}
else {
assert type instanceof BasicType<?>;
// basic type
return new SingularAttributeMetadataImpl<>(
propertyMapping,
@ -557,14 +560,15 @@ public class AttributeFactory {
private static AttributeClassification elementClassification(
org.hibernate.type.Type elementType, Value elementValue, boolean isManyToMany) {
final AttributeClassification elementClassification;
if ( elementType.isAnyType() ) {
// First, determine the type of the elements and use that to help determine the
// collection type
if ( elementType instanceof AnyType ) {
return AttributeClassification.ANY;
}
else if ( elementValue instanceof Component ) {
else if ( elementType instanceof ComponentType ) {
return AttributeClassification.EMBEDDED;
}
else if ( elementType.isAssociationType() ) {
else if ( elementType instanceof EntityType ) {
return isManyToMany ?
AttributeClassification.MANY_TO_MANY :
AttributeClassification.ONE_TO_MANY;
@ -576,13 +580,7 @@ public class AttributeFactory {
private static AttributeClassification collectionClassification(
org.hibernate.type.Type elementType, Value elementValue, boolean isManyToMany) {
if ( elementType.isAnyType() ) {
return AttributeClassification.ELEMENT_COLLECTION;
}
else if ( elementValue instanceof Component ) {
return AttributeClassification.ELEMENT_COLLECTION;
}
else if ( elementType.isAssociationType() ) {
if ( elementType instanceof EntityType ) {
return isManyToMany ?
AttributeClassification.MANY_TO_MANY :
AttributeClassification.ONE_TO_MANY;
@ -593,13 +591,13 @@ public class AttributeFactory {
}
private static AttributeClassification keyClassification(org.hibernate.type.Type keyType, Value keyValue) {
if ( keyType.isAnyType() ) {
if ( keyType instanceof AnyType ) {
return AttributeClassification.ANY;
}
else if ( keyValue instanceof Component ) {
else if ( keyType instanceof ComponentType ) {
return AttributeClassification.EMBEDDED;
}
else if ( keyType.isAssociationType() ) {
else if ( keyType instanceof EntityType ) {
return AttributeClassification.MANY_TO_ONE;
}
else {

View File

@ -14,6 +14,7 @@ import org.hibernate.mapping.Property;
import org.hibernate.metamodel.AttributeClassification;
import org.hibernate.metamodel.model.domain.ManagedDomainType;
import org.hibernate.metamodel.model.domain.internal.MapMember;
import org.hibernate.type.CollectionType;
/**
* @author Steve Ebersole
@ -87,7 +88,7 @@ public abstract class BaseAttributeMetadata<X, Y> implements AttributeMetadata<X
}
public boolean isPlural() {
return propertyMapping.getType().isCollectionType();
return propertyMapping.getType() instanceof CollectionType;
}
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.entity.EntityFetch;
import org.hibernate.sql.results.graph.entity.internal.EntityFetchJoinedImpl;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.Type;
@ -387,8 +388,8 @@ public abstract class AbstractEntityCollectionPart implements EntityCollectionPa
propertyType = entityBinding.getIdentifierMapper().getType();
}
if ( entityBinding.getIdentifierProperty() == null ) {
final CompositeType compositeType;
if ( propertyType.isComponentType() && ( compositeType = (CompositeType) propertyType ).isEmbedded()
final ComponentType compositeType;
if ( propertyType instanceof ComponentType && ( compositeType = (ComponentType) propertyType ).isEmbedded()
&& compositeType.getPropertyNames().length == 1 ) {
ToOneAttributeMapping.addPrefixedPropertyPaths(
targetKeyPropertyNames,
@ -440,8 +441,8 @@ public abstract class AbstractEntityCollectionPart implements EntityCollectionPa
}
else {
final Type propertyType = entityBinding.getRecursiveProperty( referencedPropertyName ).getType();
final CompositeType compositeType;
if ( propertyType.isComponentType() && ( compositeType = (CompositeType) propertyType ).isEmbedded()
final ComponentType compositeType;
if ( propertyType instanceof ComponentType && ( compositeType = (ComponentType) propertyType ).isEmbedded()
&& compositeType.getPropertyNames().length == 1 ) {
final Set<String> targetKeyPropertyNames = new HashSet<>( 2 );
ToOneAttributeMapping.addPrefixedPropertyPaths(

View File

@ -16,7 +16,10 @@ import org.hibernate.persister.collection.AbstractCollectionPersister;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.sql.results.graph.FetchOptions;
import org.hibernate.type.AnyType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.EntityType;
/**
* @author Steve Ebersole
@ -40,7 +43,7 @@ public final class FetchOptionsHelper {
FetchMode mappingFetchMode,
AssociationType type,
SessionFactoryImplementor sessionFactory) {
if ( !type.isEntityType() && !type.isCollectionType() ) {
if ( !( type instanceof EntityType ) && !( type instanceof CollectionType ) ) {
return FetchStyle.SELECT;
}
@ -48,7 +51,7 @@ public final class FetchOptionsHelper {
return FetchStyle.JOIN;
}
if ( type.isEntityType() ) {
if ( type instanceof EntityType ) {
EntityPersister persister = (EntityPersister) type.getAssociatedJoinable( sessionFactory );
if ( persister.isBatchLoadable() ) {
return FetchStyle.BATCH;
@ -116,11 +119,11 @@ public final class FetchOptionsHelper {
}
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
return false;
}
else if ( type.isEntityType() ) {
else if ( type instanceof EntityType ) {
final EntityPersister entityPersister = (EntityPersister) type.getAssociatedJoinable( sessionFactory );
return entityPersister.getEntityMetamodel().isLazy();
}

View File

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

View File

@ -316,7 +316,7 @@ public class MappingMetamodelImpl extends QueryParameterBindingTypeResolverImpl
);
collectionPersisterMap.put( model.getRole(), persister );
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();
Set<String> roles = collectionRolesByEntityParticipant.get( entityName );
//noinspection Java8MapApi
@ -327,7 +327,7 @@ public class MappingMetamodelImpl extends QueryParameterBindingTypeResolverImpl
roles.add( persister.getRole() );
}
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();
Set<String> roles = collectionRolesByEntityParticipant.get( entityName );
//noinspection Java8MapApi

View File

@ -134,6 +134,7 @@ import org.hibernate.sql.results.internal.SqlSelectionImpl;
import org.hibernate.type.AnyType;
import org.hibernate.type.BasicType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
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.
*/
if ( mappedByProperty != null && elementType.isEntityType() ) {
if ( mappedByProperty != null && elementType instanceof EntityType ) {
final String entityName = ( (EntityType) elementType ).getAssociatedEntityName();
final PersistentClass persistentClass = creationContext.getBootModel().getEntityBinding( entityName );
final Property property = persistentClass.getRecursiveProperty( mappedByProperty );
@ -367,7 +368,7 @@ public abstract class AbstractCollectionPersister
// ELEMENT
if ( elementType.isEntityType() ) {
if ( elementType instanceof EntityType ) {
String entityName = ( (EntityType) elementType ).getAssociatedEntityName();
elementPersister = creationContext.getDomainModel().getEntityDescriptor( entityName );
// NativeSQL: collect element column and auto-aliases
@ -418,7 +419,7 @@ public abstract class AbstractCollectionPersister
creationContext.getFunctionRegistry()
);
elementColumnIsGettable[j] = true;
if ( elementType.isComponentType() ) {
if ( elementType instanceof ComponentType || elementType instanceof AnyType ) {
// Implements desired behavior specifically for @ElementCollection mappings.
elementColumnIsSettable[j] = columnInsertability[j];
}
@ -1369,7 +1370,7 @@ public abstract class AbstractCollectionPersister
collectionPropertyColumnAliases.put( aliasName, columnAliases );
//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;
String[] propertyNames = ct.getPropertyNames();
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.internal.TableUpdateStandard;
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.sql.model.ModelMutationLogging.MODEL_MUTATION_LOGGER;
@ -751,7 +752,7 @@ public class BasicCollectionPersister extends AbstractCollectionPersister {
@Override
public boolean isManyToMany() {
return elementType.isEntityType(); //instanceof AssociationType;
return elementType instanceof EntityType; //instanceof AssociationType;
}
@Override

View File

@ -279,6 +279,7 @@ import org.hibernate.type.AnyType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.BasicType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
@ -896,7 +897,7 @@ public abstract class AbstractEntityPersister
// 2) have no associations.
// Eventually we want to be a little more lenient with associations.
for ( Type type : getSubclassPropertyTypeClosure() ) {
if ( type.isAssociationType() ) {
if ( type instanceof AnyType || type instanceof CollectionType || type instanceof EntityType ) {
return false;
}
}
@ -1432,7 +1433,7 @@ public abstract class AbstractEntityPersister
if ( hasCollections() ) {
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 can circumvent all the rest and just return the PersistentCollection
final CollectionType collectionType = (CollectionType) type;
@ -2150,7 +2151,7 @@ public abstract class AbstractEntityPersister
// // performance op to avoid the array search
// return 0;
// }
// else if ( type.isCollectionType() ) {
// else if ( type instanceof CollectionType ) {
// // properly handle property-ref-based associations
// rootPropertyName = assocType.getLHSPropertyName();
// }
@ -6101,9 +6102,9 @@ public abstract class AbstractEntityPersister
}
// aliases for composite-id's
if ( getIdentifierType().isComponentType() ) {
if ( getIdentifierType() instanceof ComponentType ) {
// 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[] idAliases = getIdentifierAliases();

View File

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

View File

@ -405,7 +405,7 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext {
String entitySuffix) {
final CollectionPersister collectionPersister = collectionReturn.getPluralAttribute().getCollectionDescriptor();
final String[] elementColumnAliases;
if ( collectionPersister.getElementType().isEntityType() ) {
if ( collectionPersister.getElementType() instanceof EntityType ) {
final EntityPersister elementPersister = collectionPersister.getElementPersister();
final String[] propertyNames = elementPersister.getPropertyNames();
final String[] identifierAliases = elementPersister.getIdentifierAliases( entitySuffix );
@ -558,13 +558,13 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext {
EntityPersister ownerPersister = alias2Persister.get( ownerAlias );
Type returnType = ownerPersister.getPropertyType( fetchReturn.getFetchableName() );
if ( returnType.isCollectionType() ) {
if ( returnType instanceof CollectionType ) {
String role = ownerPersister.getEntityName() + '.' + fetchReturn.getFetchableName();
Map<String, String[]> propertyResultsMap = Collections.emptyMap();//fetchReturn.getPropertyResultsMap()
addCollection( role, alias, propertyResultsMap );
// collectionOwnerAliases.add( ownerAlias );
}
else if ( returnType.isEntityType() ) {
else if ( returnType instanceof EntityType ) {
EntityType eType = ( EntityType ) returnType;
String returnEntityName = eType.getAssociatedEntityName();
EntityPersister persister = getSQLLoadable( returnEntityName );
@ -624,7 +624,7 @@ public class ResultSetMappingProcessor implements SQLQueryParser.ParserContext {
// }
// for ( CollectionPersister persister : alias2CollectionPersister.values() ) {
// final Type elementType = persister.getElementType();
// if ( elementType.isEntityType() && ! elementType.isAnyType() ) {
// if ( elementType instanceof EntityType && ! elementType instanceof AnyType ) {
// final Joinable joinable = ( (EntityType) elementType ).getAssociatedJoinable( factory );
// 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.RowTransformer;
import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.type.EntityType;
/**
* @author Steve Ebersole
@ -203,7 +204,7 @@ public class ResultsHelper {
);
boolean isPutFromLoad = true;
if ( collectionDescriptor.getElementType().isAssociationType() ) {
if ( collectionDescriptor.getElementType() instanceof EntityType ) {
final EntityPersister entityPersister = collectionDescriptor.getElementPersister();
for ( Object id : entry.getState() ) {
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.EntityBasedCompositionAttribute;
import org.hibernate.tuple.entity.VersionProperty;
import org.hibernate.type.AnyType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
/**
@ -218,22 +222,19 @@ public final class PropertyFactory {
}
private static NonIdentifierAttributeNature decode(Type type) {
if ( type.isAssociationType() ) {
if ( type.isComponentType() ) {
// an any type is both an association and a composite...
if ( type instanceof CollectionType ) {
return NonIdentifierAttributeNature.COLLECTION;
}
else if ( type instanceof EntityType ) {
return NonIdentifierAttributeNature.ENTITY;
}
else if ( type instanceof AnyType ) {
return NonIdentifierAttributeNature.ANY;
}
return type.isCollectionType()
? NonIdentifierAttributeNature.COLLECTION
: NonIdentifierAttributeNature.ENTITY;
}
else {
if ( type.isComponentType() ) {
else if ( type instanceof ComponentType ) {
return NonIdentifierAttributeNature.COMPOSITE;
}
else {
return NonIdentifierAttributeNature.BASIC;
}
}

View File

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

View File

@ -119,7 +119,8 @@ public abstract class AbstractType implements Type {
}
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;
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 );
if ( !collectionPersister.getElementType().isEntityType() ) {
if ( !( collectionPersister.getElementType() instanceof EntityType ) ) {
throw new MappingException(
"collection was not an association: " +
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
// an entity type, in which case we need to resolve its identifier
final Type type = entityPersister.getPropertyType( uniqueKeyPropertyName );
if ( type.isEntityType() ) {
if ( type instanceof EntityType ) {
return ( (EntityType) type ).getIdentifier( propertyValue, session );
}
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
// an entity type, in which case we need to resolve its identifier
final Type type = entityPersister.getPropertyType( uniqueKeyPropertyName );
if ( type.isEntityType() ) {
if ( type instanceof EntityType ) {
return ( (EntityType) type ).getIdentifier( propertyValue, sessionFactory );
}
else {
@ -646,7 +646,7 @@ public abstract class EntityType extends AbstractType implements AssociationType
}
else {
final Type type = factory.getReferencedPropertyType( getAssociatedEntityName(), uniqueKeyPropertyName );
if ( type.isEntityType() ) {
if ( type instanceof EntityType ) {
return ( (EntityType) type ).getIdentifierOrUniqueKeyType( factory );
}
else {

View File

@ -193,12 +193,12 @@ public class TypeHelper {
final Type type = types[i];
// AnyType is both a CompositeType and an AssociationType
// 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 );
}
else {
if ( type.isComponentType() ) {
final CompositeType compositeType = (CompositeType) type;
if ( type instanceof ComponentType ) {
final ComponentType compositeType = (ComponentType) type;
if ( target[i] != null ) {
// need to extract the component values and check for subtype replacements...
final Object[] objects = replaceCompositeAssociations(
@ -224,7 +224,7 @@ public class TypeHelper {
Map<Object, Object> copyCache,
ForeignKeyDirection foreignKeyDirection,
Object target, Object currentOriginal,
CompositeType compositeType) {
ComponentType compositeType) {
final Type[] subtypes = compositeType.getSubtypes();
return replaceAssociations(
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
// 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.
// 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()
.getMappingMetamodel()
.getEntityDescriptor( entityName ).getPropertyType( propertyName );
if ( propertyType.isCollectionType() ) {
if ( propertyType instanceof CollectionType ) {
final CollectionType collectionType = (CollectionType) propertyType;
final Type collectionElementType = collectionType.getElementType( session.getSessionFactory() );
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.Joinable;
import org.hibernate.type.CollectionType;
import org.hibernate.type.EntityType;
import org.hibernate.type.ListType;
import org.hibernate.type.MapType;
import org.hibernate.type.Type;
@ -96,7 +97,7 @@ public abstract class MockCollectionPersister implements CollectionPersister, Jo
@Override
public EntityPersister getElementPersister() {
if (elementType.isEntityType()) {
if (elementType instanceof EntityType ) {
return factory.getMetamodel()
.entityPersister(elementType.getName());
}
@ -112,7 +113,7 @@ public abstract class MockCollectionPersister implements CollectionPersister, Jo
@Override
public boolean isOneToMany() {
return elementType.isEntityType();
return elementType instanceof EntityType;
}
@Override