From 18a52483ef6c8dd99a8e8499df59ad4ae38d66cb Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Thu, 11 Jul 2019 11:13:14 -0500 Subject: [PATCH] 6 - SQM based on JPA type system - focus on reducing compilation errors --- .../internal/SessionFactoryImpl.java | 3 +- .../java/org/hibernate/loader/Loader.java | 46 ++-- .../CollectionReferenceInitializerImpl.java | 46 ++-- .../metamodel/internal/AttributeFactory.java | 58 ++--- .../internal/InflightRuntimeMetamodel.java | 170 +------------ .../metamodel/internal/MetadataContext.java | 24 +- .../internal/RuntimeModelCreationProcess.java | 21 +- .../domain/AbstractIdentifiableType.java | 5 +- .../model/domain/internal/EntityTypeImpl.java | 5 +- .../domain/internal/JpaMetamodelImpl.java | 234 ++++++++++++++---- .../internal/MappedSuperclassTypeImpl.java | 6 +- .../org/hibernate/type/CollectionType.java | 9 +- .../java/org/hibernate/type/EnumType.java | 11 +- .../jpa/test/metadata/MetadataTest.java | 5 +- 14 files changed, 307 insertions(+), 336 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java index 6a45bcd34d..8f230a0ca4 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -299,8 +299,7 @@ public void sessionFactoryClosed(SessionFactory factory) { LOG.debug( "Instantiated session factory" ); - this.metamodel = (MetamodelImplementor) metadata.getTypeConfiguration().scope( this ) - .create( metadata, determineJpaMetaModelPopulationSetting( properties ) ); + this.metamodel = (MetamodelImplementor) metadata.getTypeConfiguration().scope( this ).create( metadata ); // todo (6.0) : manage old getMultiTableBulkIdStrategy diff --git a/hibernate-core/src/main/java/org/hibernate/loader/Loader.java b/hibernate-core/src/main/java/org/hibernate/loader/Loader.java index dbba0bacd8..46f7a512f3 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/Loader.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/Loader.java @@ -26,6 +26,7 @@ import org.hibernate.HibernateException; import org.hibernate.LockMode; import org.hibernate.LockOptions; +import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.QueryException; import org.hibernate.ScrollMode; import org.hibernate.Session; @@ -38,7 +39,6 @@ import org.hibernate.cache.spi.access.EntityDataAccess; import org.hibernate.cache.spi.entry.CacheEntry; import org.hibernate.cache.spi.entry.ReferenceCacheEntryImpl; -import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.dialect.Dialect; import org.hibernate.dialect.pagination.LimitHandler; import org.hibernate.dialect.pagination.LimitHelper; @@ -1236,11 +1236,13 @@ private void endCollectionLoad( final Object resultSetId, final SharedSessionContractImplementor session, final CollectionPersister collectionPersister) { - //this is a query and we are loading multiple instances of the same collection role - session.getPersistenceContextInternal() - .getLoadContexts() - .getCollectionLoadContext( (ResultSet) resultSetId ) - .endLoadingCollections( collectionPersister ); + throw new NotYetImplementedFor6Exception( getClass() ); + +// //this is a query and we are loading multiple instances of the same collection role +// session.getPersistenceContextInternal() +// .getLoadContexts() +// .getCollectionLoadContext( (ResultSet) resultSetId ) +// .endLoadingCollections( collectionPersister ); } /** @@ -1409,13 +1411,14 @@ private void readCollectionElement( } } - PersistentCollection rowCollection = persistenceContext.getLoadContexts() - .getCollectionLoadContext( rs ) - .getLoadingCollection( persister, collectionRowKey ); - - if ( rowCollection != null ) { - rowCollection.readFrom( rs, persister, descriptor, owner ); - } + throw new NotYetImplementedFor6Exception( getClass() ); +// PersistentCollection rowCollection = persistenceContext.getLoadContexts() +// .getCollectionLoadContext( rs ) +// .getLoadingCollection( persister, collectionRowKey ); +// +// if ( rowCollection != null ) { +// rowCollection.readFrom( rs, persister, descriptor, owner ); +// } } else if ( optionalKey != null ) { @@ -1430,9 +1433,10 @@ else if ( optionalKey != null ) { ); } - persistenceContext.getLoadContexts() - .getCollectionLoadContext( rs ) - .getLoadingCollection( persister, optionalKey ); // handle empty collection + throw new NotYetImplementedFor6Exception( getClass() ); +// persistenceContext.getLoadContexts() +// .getCollectionLoadContext( rs ) +// .getLoadingCollection( persister, optionalKey ); // handle empty collection } @@ -1457,9 +1461,6 @@ private void handleEmptyCollections( CollectionPersister[] collectionPersisters = getCollectionPersisters(); final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); final boolean debugEnabled = LOG.isDebugEnabled(); - final CollectionLoadContext collectionLoadContext = persistenceContext - .getLoadContexts() - .getCollectionLoadContext( (ResultSet) resultSetId ); for ( CollectionPersister collectionPersister : collectionPersisters ) { for ( Serializable key : keys ) { //handle empty collections @@ -1470,8 +1471,11 @@ private void handleEmptyCollections( ); } - collectionLoadContext - .getLoadingCollection( collectionPersister, key ); + throw new NotYetImplementedFor6Exception( getClass() ); +// session.getPersistenceContext() +// .getLoadContexts() +// .getCollectionLoadContext( (ResultSet) resultSetId ) +// .getLoadingCollection( collectionPersister, key ); } } } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/CollectionReferenceInitializerImpl.java b/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/CollectionReferenceInitializerImpl.java index 2d97519e84..99ae488605 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/CollectionReferenceInitializerImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/CollectionReferenceInitializerImpl.java @@ -10,6 +10,7 @@ import java.sql.ResultSet; import java.sql.SQLException; +import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.internal.CoreLogging; @@ -66,20 +67,22 @@ public void finishUpRow(ResultSet resultSet, ResultSetProcessingContextImpl cont ); } - Object collectionOwner = findCollectionOwner( collectionRowKey, resultSet, context ); - PersistentCollection rowCollection = persistenceContext.getLoadContexts() - .getCollectionLoadContext( resultSet ) - .getLoadingCollection( collectionReference.getCollectionPersister(), collectionRowKey ); + throw new NotYetImplementedFor6Exception( getClass() ); - if ( rowCollection != null ) { - rowCollection.readFrom( - resultSet, - collectionReference.getCollectionPersister(), - aliases.getCollectionColumnAliases(), - collectionOwner - ); - } +// Object collectionOwner = findCollectionOwner( collectionRowKey, resultSet, context ); +// PersistentCollection rowCollection = persistenceContext.getLoadContexts() +// .getCollectionLoadContext( resultSet ) +// .getLoadingCollection( collectionReference.getCollectionPersister(), collectionRowKey ); +// +// if ( rowCollection != null ) { +// rowCollection.readFrom( +// resultSet, +// collectionReference.getCollectionPersister(), +// aliases.getCollectionColumnAliases(), +// collectionOwner +// ); +// } } else { @@ -99,10 +102,12 @@ public void finishUpRow(ResultSet resultSet, ResultSetProcessingContextImpl cont ) ); } - // handle empty collection - persistenceContext.getLoadContexts() - .getCollectionLoadContext( resultSet ) - .getLoadingCollection( collectionReference.getCollectionPersister(), optionalKey ); + + throw new NotYetImplementedFor6Exception( getClass() ); +// // handle empty collection +// persistenceContext.getLoadContexts() +// .getCollectionLoadContext( resultSet ) +// .getLoadingCollection( collectionReference.getCollectionPersister(), optionalKey ); } } @@ -148,9 +153,10 @@ protected Serializable findCollectionOwnerKey(ResultSetProcessingContextImpl con @Override public void endLoading(ResultSetProcessingContextImpl context) { - context.getSession().getPersistenceContextInternal() - .getLoadContexts() - .getCollectionLoadContext( context.getResultSet() ) - .endLoadingCollections( collectionReference.getCollectionPersister() ); + throw new NotYetImplementedFor6Exception( getClass() ); +// context.getSession().getPersistenceContextInternal() +// .getLoadContexts() +// .getCollectionLoadContext( context.getResultSet() ) +// .endLoadingCollections( collectionReference.getCollectionPersister() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java index 5aa4369ae5..93b27090ea 100755 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java @@ -19,7 +19,6 @@ import javax.persistence.metamodel.PluralAttribute; import javax.persistence.metamodel.Type; -import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.annotations.common.AssertionFailure; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.internal.EntityManagerMessageLogger; @@ -492,32 +491,32 @@ private interface MemberResolver { private AttributeMetadata determineAttributeMetadata( AttributeContext attributeContext, MemberResolver memberResolver) { - LOG.trace( - "Starting attribute metadata determination [" + attributeContext.getPropertyMapping() - .getName() + "]" - ); + final Property propertyMapping = attributeContext.getPropertyMapping(); + final String propertyName = propertyMapping.getName(); + + LOG.trace( "Starting attribute metadata determination [" + propertyName + "]" ); + final Member member = memberResolver.resolveMember( attributeContext ); LOG.trace( " Determined member [" + member + "]" ); - final Value value = attributeContext.getPropertyMapping().getValue(); + final Value value = propertyMapping.getValue(); final org.hibernate.type.Type type = value.getType(); LOG.trace( " Determined type [name=" + type.getName() + ", class=" + type.getClass().getName() + "]" ); if ( type.isAnyType() ) { - // ANY mappings are currently not supported in the JPA metamodel; see HHH-6589 - if ( context.isIgnoreUnsupported() ) { - return null; - } - else { - throw new UnsupportedOperationException( "ANY not supported" ); - } + return new SingularAttributeMetadataImpl<>( + propertyMapping, + attributeContext.getOwnerType(), + member, + AttributeClassification.ANY + ); } else if ( type.isAssociationType() ) { // collection or entity if ( type.isEntityType() ) { // entity return new SingularAttributeMetadataImpl( - attributeContext.getPropertyMapping(), + propertyMapping, attributeContext.getOwnerType(), member, determineSingularAssociationClassification( member ) @@ -528,21 +527,17 @@ else if ( type.isAssociationType() ) { final Collection collValue = (Collection) value; final Value elementValue = collValue.getElement(); final org.hibernate.type.Type elementType = elementValue.getType(); + final boolean isManyToMany = isManyToMany( member ); // First, determine the type of the elements and use that to help determine the // collection type) final AttributeClassification elementClassification; final AttributeClassification attributeClassification; if ( elementType.isAnyType() ) { - if ( context.isIgnoreUnsupported() ) { - return null; - } - else { - throw new UnsupportedOperationException( "collection of any not supported yet" ); - } + attributeClassification = AttributeClassification.ELEMENT_COLLECTION; + elementClassification = AttributeClassification.ANY; } - final boolean isManyToMany = isManyToMany( member ); - if ( elementValue instanceof Component ) { + else if ( elementValue instanceof Component ) { elementClassification = AttributeClassification.EMBEDDED; attributeClassification = AttributeClassification.ELEMENT_COLLECTION; } @@ -565,14 +560,9 @@ else if ( elementType.isAssociationType() ) { final org.hibernate.type.Type keyType = keyValue.getType(); if ( keyType.isAnyType() ) { - if ( context.isIgnoreUnsupported() ) { - return null; - } - else { - throw new UnsupportedOperationException( "collection of any not supported yet" ); - } + indexClassification = AttributeClassification.ANY; } - if ( keyValue instanceof Component ) { + else if ( keyValue instanceof Component ) { indexClassification = AttributeClassification.EMBEDDED; } else if ( keyType.isAssociationType() ) { @@ -589,7 +579,7 @@ else if ( value instanceof List ) { indexClassification = null; } return new PluralAttributeMetadataImpl( - attributeContext.getPropertyMapping(), + propertyMapping, attributeContext.getOwnerType(), member, attributeClassification, @@ -617,10 +607,10 @@ else if ( value instanceof OneToMany ) { // ); } } - else if ( attributeContext.getPropertyMapping().isComposite() ) { + else if ( propertyMapping.isComposite() ) { // component return new SingularAttributeMetadataImpl<>( - attributeContext.getPropertyMapping(), + propertyMapping, attributeContext.getOwnerType(), member, AttributeClassification.EMBEDDED @@ -629,13 +619,13 @@ else if ( attributeContext.getPropertyMapping().isComposite() ) { else { // basic type return new SingularAttributeMetadataImpl<>( - attributeContext.getPropertyMapping(), + propertyMapping, attributeContext.getOwnerType(), member, AttributeClassification.BASIC ); } - throw new UnsupportedOperationException( "oops, we are missing something: " + attributeContext.getPropertyMapping() ); + throw new UnsupportedOperationException( "oops, we are missing something: " + propertyMapping ); } public static AttributeClassification determineSingularAssociationClassification(Member member) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/InflightRuntimeMetamodel.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/InflightRuntimeMetamodel.java index cdf986bdf6..dca1d6fb62 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/InflightRuntimeMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/InflightRuntimeMetamodel.java @@ -24,25 +24,16 @@ import org.hibernate.internal.EntityManagerMessageLogger; import org.hibernate.internal.HEMLogging; import org.hibernate.mapping.Collection; -import org.hibernate.mapping.MappedSuperclass; import org.hibernate.mapping.PersistentClass; -import org.hibernate.metamodel.model.domain.EmbeddableDomainType; -import org.hibernate.metamodel.model.domain.EntityDomainType; -import org.hibernate.metamodel.model.domain.IdentifiableDomainType; -import org.hibernate.metamodel.model.domain.MappedSuperclassDomainType; import org.hibernate.metamodel.model.domain.NavigableRole; -import org.hibernate.metamodel.model.domain.internal.EntityTypeImpl; -import org.hibernate.metamodel.model.domain.internal.MappedSuperclassTypeImpl; import org.hibernate.metamodel.spi.RuntimeModelCreationContext; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.spi.PersisterCreationContext; import org.hibernate.persister.spi.PersisterFactory; -import org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder; import org.hibernate.tuple.entity.EntityTuplizer; import org.hibernate.type.EntityType; import org.hibernate.type.Type; -import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.spi.TypeConfiguration; /** @@ -63,14 +54,6 @@ public class InflightRuntimeMetamodel { private final Map> collectionRolesByEntityParticipant = new ConcurrentHashMap<>(); - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // JPA metamodel - - private final Map> jpaEntityTypeMap = new ConcurrentHashMap<>(); - private final Map, MappedSuperclassDomainType> jpaMappedSuperclassTypeMap = new ConcurrentHashMap<>(); - private Map> jpaEmbeddableDescriptorMap = new ConcurrentHashMap<>(); - - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Misc @@ -84,12 +67,9 @@ public InflightRuntimeMetamodel(TypeConfiguration typeConfiguration) { public void processBootMetaModel( MetadataImplementor bootMetamodel, - SqmCriteriaNodeBuilder criteriaBuilder, CacheImplementor cacheImplementor, PersisterFactory persisterFactory, - RuntimeModelCreationContext modelCreationContext, - JpaMetaModelPopulationSetting jpaMetaModelPopulationSetting, - JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting) { + RuntimeModelCreationContext modelCreationContext) { this.imports.putAll( bootMetamodel.getImports() ); processBootEntities( bootMetamodel.getEntityBindings(), @@ -107,13 +87,6 @@ public void processBootMetaModel( finishDomainMetamodelInitialization(); - processJpa( - bootMetamodel, - criteriaBuilder, - jpaMetaModelPopulationSetting, - jpaStaticMetaModelPopulationSetting - ); - } public TypeConfiguration getTypeConfiguration() { @@ -136,18 +109,6 @@ public Map> getCollectionRolesByEntityParticipant() { return collectionRolesByEntityParticipant; } - public Map> getJpaEntityTypeMap() { - return jpaEntityTypeMap; - } - - public Map, MappedSuperclassDomainType> getJpaMappedSuperclassTypeMap() { - return jpaMappedSuperclassTypeMap; - } - - public Map> getJpaEmbeddableDescriptorMap() { - return jpaEmbeddableDescriptorMap; - } - public Map getNameToImportNameMap() { return nameToImportNameMap; } @@ -178,40 +139,6 @@ public EntityPersister findEntityDescriptor(String entityName) { return entityPersisterMap.get( entityName ); } - private void processJpa( - MetadataImplementor bootMetamodel, - SqmCriteriaNodeBuilder criteriaBuilder, - JpaMetaModelPopulationSetting jpaMetaModelPopulationSetting, - JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting) { - if ( jpaMetaModelPopulationSetting != JpaMetaModelPopulationSetting.DISABLED ) { - MetadataContext context = new MetadataContext( - this, - criteriaBuilder, - bootMetamodel.getMappedSuperclassMappingsCopy(), - typeConfiguration, - jpaMetaModelPopulationSetting, - jpaStaticMetaModelPopulationSetting - ); - - for ( PersistentClass entityBinding : bootMetamodel.getEntityBindings() ) { - locateOrBuildEntityType( entityBinding, context, typeConfiguration ); - } - handleUnusedMappedSuperclasses( context, typeConfiguration ); - - context.wrapUp(); - - this.nameToImportNameMap.putAll( bootMetamodel.getImports() ); - - this.jpaEntityTypeMap.putAll( context.getEntityTypesByEntityName() ); - this.jpaMappedSuperclassTypeMap.putAll( context.getMappedSuperclassTypeMap() ); - - for ( EmbeddableDomainType embeddable : context.getEmbeddableTypeSet() ) { - this.jpaEmbeddableDescriptorMap.put( embeddable.getJavaType(), embeddable ); - } - - } - } - private void processBootEntities( java.util.Collection entityBindings, CacheImplementor cacheImplementor, @@ -339,101 +266,6 @@ private static void registerEntityNameResolvers( } } - private static void handleUnusedMappedSuperclasses(MetadataContext context, TypeConfiguration typeConfiguration) { - final Set unusedMappedSuperclasses = context.getUnusedMappedSuperclasses(); - if ( !unusedMappedSuperclasses.isEmpty() ) { - for ( MappedSuperclass mappedSuperclass : unusedMappedSuperclasses ) { - log.unusedMappedSuperclass( mappedSuperclass.getMappedClass().getName() ); - locateOrBuildMappedSuperclassType( mappedSuperclass, context, typeConfiguration ); - } - } - } - - private static MappedSuperclassDomainType locateOrBuildMappedSuperclassType( - MappedSuperclass mappedSuperclass, - MetadataContext context, - TypeConfiguration typeConfiguration) { - MappedSuperclassDomainType mappedSuperclassType = context.locateMappedSuperclassType( mappedSuperclass ); - if ( mappedSuperclassType == null ) { - mappedSuperclassType = buildMappedSuperclassType( mappedSuperclass, context, typeConfiguration ); - } - return mappedSuperclassType; - } - - @SuppressWarnings("unchecked") - private static MappedSuperclassTypeImpl buildMappedSuperclassType( - MappedSuperclass mappedSuperclass, - MetadataContext context, - TypeConfiguration typeConfiguration) { - final MappedSuperclass superMappedSuperclass = mappedSuperclass.getSuperMappedSuperclass(); - IdentifiableDomainType superType = superMappedSuperclass == null - ? null - : locateOrBuildMappedSuperclassType( superMappedSuperclass, context, typeConfiguration ); - //no mappedSuperclass, check for a super entity - if ( superType == null ) { - final PersistentClass superPersistentClass = mappedSuperclass.getSuperPersistentClass(); - superType = superPersistentClass == null - ? null - : locateOrBuildEntityType( superPersistentClass, context, typeConfiguration ); - } - final JavaTypeDescriptor javaTypeDescriptor = context.getTypeConfiguration() - .getJavaTypeDescriptorRegistry() - .getDescriptor( mappedSuperclass.getMappedClass() ); - MappedSuperclassTypeImpl mappedSuperclassType = new MappedSuperclassTypeImpl( - javaTypeDescriptor, - mappedSuperclass, - superType, - typeConfiguration - ); - - context.registerMappedSuperclassType( mappedSuperclass, mappedSuperclassType ); - return mappedSuperclassType; - } - - private static EntityDomainType locateOrBuildEntityType( - PersistentClass persistentClass, - MetadataContext context, - TypeConfiguration typeConfiguration) { - EntityDomainType entityType = context.locateEntityType( persistentClass ); - if ( entityType == null ) { - entityType = buildEntityType( persistentClass, context, typeConfiguration ); - } - return entityType; - } - - @SuppressWarnings("unchecked") - private static EntityTypeImpl buildEntityType( - PersistentClass persistentClass, - MetadataContext context, - TypeConfiguration typeConfiguration) { - final Class javaType = persistentClass.getMappedClass(); - context.pushEntityWorkedOn( persistentClass ); - final MappedSuperclass superMappedSuperclass = persistentClass.getSuperMappedSuperclass(); - IdentifiableDomainType superType = superMappedSuperclass == null - ? null - : locateOrBuildMappedSuperclassType( superMappedSuperclass, context, typeConfiguration ); - //no mappedSuperclass, check for a super entity - if ( superType == null ) { - final PersistentClass superPersistentClass = persistentClass.getSuperclass(); - superType = superPersistentClass == null - ? null - : locateOrBuildEntityType( superPersistentClass, context, typeConfiguration ); - } - - final JavaTypeDescriptor javaTypeDescriptor = context.getTypeConfiguration() - .getJavaTypeDescriptorRegistry() - .getDescriptor( javaType ); - EntityTypeImpl entityType = new EntityTypeImpl( - javaTypeDescriptor, - superType, - persistentClass, - typeConfiguration - ); - context.registerEntityType( persistentClass, entityType ); - context.popEntityWorkedOn( persistentClass ); - return entityType; - } - public Map getImports() { return imports; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java index 8ba01b47f6..a4869a55c9 100755 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java @@ -20,6 +20,7 @@ import javax.persistence.metamodel.SingularAttribute; import javax.persistence.metamodel.Type; +import org.hibernate.Internal; import org.hibernate.annotations.common.AssertionFailure; import org.hibernate.internal.EntityManagerMessageLogger; import org.hibernate.internal.HEMLogging; @@ -62,7 +63,8 @@ * @author Steve Ebersole * @author Emmanuel Bernard */ -class MetadataContext { +@Internal +public class MetadataContext { private static final EntityManagerMessageLogger LOG = HEMLogging.messageLogger( MetadataContext.class ); private final RuntimeModelCreationContext runtimeModelCreationContext; @@ -70,7 +72,6 @@ class MetadataContext { private final SqmCriteriaNodeBuilder criteriaBuilder; private Set knownMappedSuperclasses; private TypeConfiguration typeConfiguration; - private final boolean ignoreUnsupported; private final JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting; private final AttributeFactory attributeFactory = new AttributeFactory( this ); @@ -97,15 +98,12 @@ public MetadataContext( InflightRuntimeMetamodel metamodel, SqmCriteriaNodeBuilder criteriaBuilder, Set mappedSuperclasses, - TypeConfiguration typeConfiguration, - JpaMetaModelPopulationSetting jpaMetaModelPopulationSetting, JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting) { this.runtimeModelCreationContext = runtimeModelCreationContext; this.metamodel = metamodel; this.criteriaBuilder = criteriaBuilder; this.knownMappedSuperclasses = mappedSuperclasses; - this.typeConfiguration = typeConfiguration; - this.ignoreUnsupported = jpaMetaModelPopulationSetting == JpaMetaModelPopulationSetting.IGNORE_UNSUPPORTED; + this.typeConfiguration = runtimeModelCreationContext.getTypeConfiguration(); this.jpaStaticMetaModelPopulationSetting = jpaStaticMetaModelPopulationSetting; } @@ -129,10 +127,6 @@ InflightRuntimeMetamodel getMetamodel() { return metamodel; } - /*package*/ boolean isIgnoreUnsupported() { - return ignoreUnsupported; - } - /** * Retrieves the {@linkplain Class java type} to {@link EntityTypeImpl} map. * @@ -162,11 +156,7 @@ public Map, MappedSuperclassDomainType> getMappedSuperclassTypeMap() return mappedSuperClassTypeMap; } - /*package*/ void registerEntityType(PersistentClass persistentClass, EntityTypeImpl entityType) { - if ( ignoreUnsupported && entityType.getBindableJavaType() == null ) { - return; - } - + public void registerEntityType(PersistentClass persistentClass, EntityTypeImpl entityType) { if ( entityType.getBindableJavaType() != null ) { entityTypes.put( entityType.getBindableJavaType(), entityType ); } @@ -176,14 +166,14 @@ public Map, MappedSuperclassDomainType> getMappedSuperclassTypeMap() orderedMappings.add( persistentClass ); } - /*package*/ void registerEmbeddableType(EmbeddableDomainType embeddableType) { + public void registerEmbeddableType(EmbeddableDomainType embeddableType) { assert embeddableType.getJavaType() != null; assert ! Map.class.isAssignableFrom( embeddableType.getJavaType() ); embeddables.put( embeddableType.getJavaType(), embeddableType ); } - /*package*/ void registerMappedSuperclassType( + public void registerMappedSuperclassType( MappedSuperclass mappedSuperclass, MappedSuperclassDomainType mappedSuperclassType) { mappedSuperclassByMappedSuperclassMapping.put( mappedSuperclass, mappedSuperclassType ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/RuntimeModelCreationProcess.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/RuntimeModelCreationProcess.java index f0b3a1db0e..990520e247 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/RuntimeModelCreationProcess.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/RuntimeModelCreationProcess.java @@ -100,10 +100,8 @@ public RuntimeModelCreationProcess( * Perform the runtime metamodel creation based on the information obtained during * the first phase of booting, returning the */ - public DomainMetamodel create( - MetadataImplementor bootMetamodel, - JpaMetaModelPopulationSetting jpaMetaModelPopulationSetting) { - final RuntimeModelCreationContext persisterCreationContext = new RuntimeModelCreationContext() { + public DomainMetamodel create(MetadataImplementor bootMetamodel) { + final RuntimeModelCreationContext runtimeModelCreationContext = new RuntimeModelCreationContext() { @Override public BootstrapContext getBootstrapContext() { return bootstrapContext; @@ -126,20 +124,21 @@ public MetadataImplementor getMetadata() { primeSecondLevelCacheRegions( bootMetamodel ); + final JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting = determineJpaMetaModelPopulationSetting( sessionFactory.getProperties() ); + inflightRuntimeMetamodel.processBootMetaModel( bootMetamodel, - sessionFactory.getQueryEngine().getCriteriaBuilder(), sessionFactory.getCache(), persisterFactory, - persisterCreationContext, - jpaMetaModelPopulationSetting, - determineJpaMetaModelPopulationSetting( - sessionFactory.getProperties() ) - + runtimeModelCreationContext ); - final JpaMetamodel jpaMetamodel = new JpaMetamodelImpl( + final JpaMetamodel jpaMetamodel = JpaMetamodelImpl.buildMetamodel( + runtimeModelCreationContext, + bootMetamodel, inflightRuntimeMetamodel, + sessionFactory.getQueryEngine().getCriteriaBuilder(), + jpaStaticMetaModelPopulationSetting, bootMetamodel.getNamedEntityGraphs().values() ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractIdentifiableType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractIdentifiableType.java index d0a52ab811..9961297736 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractIdentifiableType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractIdentifiableType.java @@ -15,7 +15,6 @@ import org.hibernate.metamodel.model.domain.internal.AttributeContainer; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; -import org.hibernate.type.spi.TypeConfiguration; /** * Defines commonality for the JPA {@link IdentifiableType} types. JPA defines @@ -47,8 +46,8 @@ public AbstractIdentifiableType( boolean hasIdClass, boolean hasIdentifierProperty, boolean versioned, - TypeConfiguration typeConfiguration) { - super( typeName, javaTypeDescriptor, superType, typeConfiguration ); + JpaMetamodel jpaMetamodel) { + super( typeName, javaTypeDescriptor, superType, jpaMetamodel ); this.hasIdClass = hasIdClass; this.hasIdentifierProperty = hasIdentifierProperty; this.isVersioned = versioned; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java index 4f33712a2f..425cd73027 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java @@ -21,7 +21,6 @@ import org.hibernate.query.sqm.produce.spi.SqmCreationState; import org.hibernate.query.sqm.tree.domain.SqmPath; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; -import org.hibernate.type.spi.TypeConfiguration; /** * Defines the Hibernate implementation of the JPA {@link EntityType} contract. @@ -38,7 +37,7 @@ public EntityTypeImpl( JavaTypeDescriptor javaTypeDescriptor, IdentifiableDomainType superType, PersistentClass persistentClass, - TypeConfiguration typeConfiguration) { + JpaMetamodel jpaMetamodel) { super( persistentClass.getEntityName(), javaTypeDescriptor, @@ -46,7 +45,7 @@ public EntityTypeImpl( persistentClass.getDeclaredIdentifierMapper() != null || ( superType != null && superType.hasIdClass() ), persistentClass.hasIdentifierProperty(), persistentClass.isVersioned(), - typeConfiguration + jpaMetamodel ); this.jpaEntityName = persistentClass.getJpaEntityName(); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java index 25a7c366cc..5ccf58c8f0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java @@ -24,6 +24,7 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; +import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.cfg.annotations.NamedEntityGraphDefinition; import org.hibernate.graph.internal.RootGraphImpl; import org.hibernate.graph.spi.AttributeNodeImplementor; @@ -34,14 +35,21 @@ import org.hibernate.internal.HEMLogging; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.CollectionHelper; +import org.hibernate.mapping.MappedSuperclass; +import org.hibernate.mapping.PersistentClass; import org.hibernate.metamodel.internal.InflightRuntimeMetamodel; -import org.hibernate.metamodel.model.domain.AbstractDomainType; +import org.hibernate.metamodel.internal.JpaStaticMetaModelPopulationSetting; +import org.hibernate.metamodel.internal.MetadataContext; import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.metamodel.model.domain.EntityDomainType; +import org.hibernate.metamodel.model.domain.IdentifiableDomainType; import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.metamodel.model.domain.ManagedDomainType; import org.hibernate.metamodel.model.domain.MappedSuperclassDomainType; +import org.hibernate.metamodel.spi.RuntimeModelCreationContext; +import org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder; import org.hibernate.query.sqm.tree.domain.SqmPolymorphicRootDescriptor; +import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.hibernate.type.spi.TypeConfiguration; /** @@ -53,13 +61,9 @@ public class JpaMetamodelImpl implements JpaMetamodel { private final TypeConfiguration typeConfiguration; - private final Map> entityDescriptorMap; - - private final Map, MappedSuperclassDomainType> mappedSuperclassTypeMap; - - private final Map> embeddableDescriptorMap; - - private final Map nameToImportNameMap; + private final Map> jpaEntityTypeMap = new ConcurrentHashMap<>(); + private final Map, MappedSuperclassDomainType> jpaMappedSuperclassTypeMap = new ConcurrentHashMap<>(); + private final Map> jpaEmbeddableDescriptorMap = new ConcurrentHashMap<>(); private final transient Map entityGraphMap = new ConcurrentHashMap<>(); @@ -67,26 +71,14 @@ public class JpaMetamodelImpl implements JpaMetamodel { private final Map entityProxyInterfaceMap; + private final Map nameToImportNameMap; - public JpaMetamodelImpl( - InflightRuntimeMetamodel runtimeMetamodel, - java.util.Collection namedEntityGraphDefinitions) { + + public JpaMetamodelImpl(InflightRuntimeMetamodel runtimeMetamodel) { this.typeConfiguration = runtimeMetamodel.getTypeConfiguration(); - entityDescriptorMap = runtimeMetamodel.getJpaEntityTypeMap(); - mappedSuperclassTypeMap = runtimeMetamodel.getJpaMappedSuperclassTypeMap(); - embeddableDescriptorMap = runtimeMetamodel.getJpaEmbeddableDescriptorMap(); - -// entityDescriptorMap.values() -// .forEach( domainType -> ( (AbstractDomainType) domainType ).injectJpaMetamodel( this ) ); -// mappedSuperclassTypeMap.values().forEach( domainType -> ( (AbstractDomainType) domainType ).injectJpaMetamodel( -// this ) ); -// entityDescriptorMap.values() -// .forEach( domainType -> ( (AbstractDomainType) domainType ).injectJpaMetamodel( this ) ); - nameToImportNameMap = runtimeMetamodel.getNameToImportNameMap(); entityProxyInterfaceMap = runtimeMetamodel.getEntityProxyInterfaceMap(); - applyNamedEntityGraphs( namedEntityGraphDefinitions ); } @Override @@ -97,7 +89,7 @@ public TypeConfiguration getTypeConfiguration() { @Override public EntityDomainType entity(String entityName) { //noinspection unchecked - return (EntityDomainType) entityDescriptorMap.get( entityName ); + return (EntityDomainType) jpaEntityTypeMap.get( entityName ); } @Override @@ -125,17 +117,17 @@ public EntityDomainType resolveHqlEntityReference(String entityName) { public void visitManagedTypes(Consumer> action) { visitEntityTypes( (Consumer) action ); visitEmbeddables( (Consumer) action ); - mappedSuperclassTypeMap.values().forEach( action ); + jpaMappedSuperclassTypeMap.values().forEach( action ); } @Override public ManagedDomainType findManagedType(Class cls) { - ManagedType type = entityDescriptorMap.get( cls ); + ManagedType type = jpaEntityTypeMap.get( cls ); if ( type == null ) { - type = mappedSuperclassTypeMap.get( cls ); + type = jpaMappedSuperclassTypeMap.get( cls ); } if ( type == null ) { - type = embeddableDescriptorMap.get( cls ); + type = jpaEmbeddableDescriptorMap.get( cls ); } if ( type == null ) { return null; @@ -147,12 +139,12 @@ public ManagedDomainType findManagedType(Class cls) { @Override public void visitEntityTypes(Consumer> action) { - entityDescriptorMap.values().forEach( action ); + jpaEntityTypeMap.values().forEach( action ); } @Override public EntityDomainType findEntityType(Class cls) { - final EntityType entityType = entityDescriptorMap.get( cls ); + final EntityType entityType = jpaEntityTypeMap.get( cls ); if ( entityType == null ) { return null; } @@ -162,7 +154,7 @@ public EntityDomainType findEntityType(Class cls) { @Override public void visitRootEntityTypes(Consumer> action) { - entityDescriptorMap.values().forEach( + jpaEntityTypeMap.values().forEach( entityDomainType -> { if ( entityDomainType.getSuperType() == null ) { action.accept( entityDomainType ); @@ -173,17 +165,17 @@ public void visitRootEntityTypes(Consumer> action) { @Override public void visitEmbeddables(Consumer> action) { - embeddableDescriptorMap.values().forEach( action ); + jpaEmbeddableDescriptorMap.values().forEach( action ); } @Override public ManagedDomainType managedType(Class cls) { - ManagedType type = entityDescriptorMap.get( cls ); + ManagedType type = jpaEntityTypeMap.get( cls ); if ( type == null ) { - type = mappedSuperclassTypeMap.get( cls ); + type = jpaMappedSuperclassTypeMap.get( cls ); } if ( type == null ) { - type = embeddableDescriptorMap.get( cls ); + type = jpaEmbeddableDescriptorMap.get( cls ); } if ( type == null ) { // per JPA @@ -196,7 +188,7 @@ public ManagedDomainType managedType(Class cls) { @Override public EntityDomainType entity(Class cls) { - final EntityType entityType = entityDescriptorMap.get( cls ); + final EntityType entityType = jpaEntityTypeMap.get( cls ); if ( entityType == null ) { throw new IllegalArgumentException( "Not an entity: " + cls ); } @@ -206,7 +198,7 @@ public EntityDomainType entity(Class cls) { @Override public EmbeddableDomainType embeddable(Class cls) { - final EmbeddableDomainType embeddableType = embeddableDescriptorMap.get( cls ); + final EmbeddableDomainType embeddableType = jpaEmbeddableDescriptorMap.get( cls ); if ( embeddableType == null ) { throw new IllegalArgumentException( "Not an embeddable: " + cls ); } @@ -217,23 +209,23 @@ public EmbeddableDomainType embeddable(Class cls) { @Override public Set> getManagedTypes() { final int setSize = CollectionHelper.determineProperSizing( - entityDescriptorMap.size() + mappedSuperclassTypeMap.size() + embeddableDescriptorMap.size() + jpaEntityTypeMap.size() + jpaMappedSuperclassTypeMap.size() + jpaEmbeddableDescriptorMap.size() ); final Set> managedTypes = new HashSet<>( setSize ); - managedTypes.addAll( entityDescriptorMap.values() ); - managedTypes.addAll( mappedSuperclassTypeMap.values() ); - managedTypes.addAll( embeddableDescriptorMap.values() ); + managedTypes.addAll( jpaEntityTypeMap.values() ); + managedTypes.addAll( jpaMappedSuperclassTypeMap.values() ); + managedTypes.addAll( jpaEmbeddableDescriptorMap.values() ); return managedTypes; } @Override public Set> getEntities() { - return new HashSet<>( entityDescriptorMap.values() ); + return new HashSet<>( jpaEntityTypeMap.values() ); } @Override public Set> getEmbeddables() { - return new HashSet<>( embeddableDescriptorMap.values() ); + return new HashSet<>( jpaEmbeddableDescriptorMap.values() ); } @Override @@ -405,7 +397,7 @@ private Class resolveRequestedClass(String entityName) { public EntityDomainType resolveEntityReference(Class javaType) { // try the incoming Java type as a "strict" entity reference { - final EntityDomainType descriptor = entityDescriptorMap.get( javaType ); + final EntityDomainType descriptor = jpaEntityTypeMap.get( javaType ); if ( descriptor != null ) { return (EntityDomainType) descriptor; } @@ -415,7 +407,7 @@ public EntityDomainType resolveEntityReference(Class javaType) { { final String proxyEntityName = entityProxyInterfaceMap.get( javaType ); if ( proxyEntityName != null ) { - return (EntityDomainType) entityDescriptorMap.get( proxyEntityName ); + return (EntityDomainType) jpaEntityTypeMap.get( proxyEntityName ); } } @@ -445,4 +437,156 @@ public EntityDomainType resolveEntityReference(Class javaType) { throw new IllegalArgumentException( "Could not resolve entity reference : " + javaType.getName() ); } + + public static JpaMetamodel buildMetamodel( + RuntimeModelCreationContext runtimeModelCreationContext, + MetadataImplementor bootMetamodel, + InflightRuntimeMetamodel inflightRuntimeMetamodel, + SqmCriteriaNodeBuilder criteriaBuilder, + JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting, + java.util.Collection namedEntityGraphDefinitions) { + final JpaMetamodelImpl jpaMetamodel = new JpaMetamodelImpl( inflightRuntimeMetamodel ); + + jpaMetamodel.processJpa( + runtimeModelCreationContext, + bootMetamodel, + inflightRuntimeMetamodel, + criteriaBuilder, + jpaStaticMetaModelPopulationSetting, + namedEntityGraphDefinitions + ); + + return jpaMetamodel; + } + + private void processJpa( + RuntimeModelCreationContext runtimeModelCreationContext, + MetadataImplementor bootMetamodel, + InflightRuntimeMetamodel inflightRuntimeMetamodel, + SqmCriteriaNodeBuilder criteriaBuilder, + JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting, + java.util.Collection namedEntityGraphDefinitions) { + if ( jpaStaticMetaModelPopulationSetting != JpaStaticMetaModelPopulationSetting.DISABLED ) { + MetadataContext context = new MetadataContext( + runtimeModelCreationContext, + inflightRuntimeMetamodel, + criteriaBuilder, + bootMetamodel.getMappedSuperclassMappingsCopy(), + jpaStaticMetaModelPopulationSetting + ); + + for ( PersistentClass entityBinding : bootMetamodel.getEntityBindings() ) { + locateOrBuildEntityType( entityBinding, context, typeConfiguration ); + } + handleUnusedMappedSuperclasses( context, typeConfiguration ); + + context.wrapUp(); + + this.nameToImportNameMap.putAll( bootMetamodel.getImports() ); + + this.jpaEntityTypeMap.putAll( context.getEntityTypesByEntityName() ); + this.jpaMappedSuperclassTypeMap.putAll( context.getMappedSuperclassTypeMap() ); + + for ( EmbeddableDomainType embeddable : context.getEmbeddableTypeSet() ) { + this.jpaEmbeddableDescriptorMap.put( embeddable.getJavaType(), embeddable ); + } + } + + applyNamedEntityGraphs( namedEntityGraphDefinitions ); + } + + private EntityDomainType locateOrBuildEntityType( + PersistentClass persistentClass, + MetadataContext context, + TypeConfiguration typeConfiguration) { + EntityDomainType entityType = context.locateEntityType( persistentClass ); + if ( entityType == null ) { + entityType = buildEntityType( persistentClass, context, typeConfiguration ); + } + return entityType; + } + + @SuppressWarnings("unchecked") + private EntityTypeImpl buildEntityType( + PersistentClass persistentClass, + MetadataContext context, + TypeConfiguration typeConfiguration) { + final Class javaType = persistentClass.getMappedClass(); + context.pushEntityWorkedOn( persistentClass ); + final MappedSuperclass superMappedSuperclass = persistentClass.getSuperMappedSuperclass(); + IdentifiableDomainType superType = superMappedSuperclass == null + ? null + : locateOrBuildMappedSuperclassType( superMappedSuperclass, context, typeConfiguration ); + //no mappedSuperclass, check for a super entity + if ( superType == null ) { + final PersistentClass superPersistentClass = persistentClass.getSuperclass(); + superType = superPersistentClass == null + ? null + : locateOrBuildEntityType( superPersistentClass, context, typeConfiguration ); + } + + final JavaTypeDescriptor javaTypeDescriptor = context.getTypeConfiguration() + .getJavaTypeDescriptorRegistry() + .getDescriptor( javaType ); + final EntityTypeImpl entityType = new EntityTypeImpl( + javaTypeDescriptor, + superType, + persistentClass, + this + ); + context.registerEntityType( persistentClass, entityType ); + context.popEntityWorkedOn( persistentClass ); + return entityType; + } + + private void handleUnusedMappedSuperclasses(MetadataContext context, TypeConfiguration typeConfiguration) { + final Set unusedMappedSuperclasses = context.getUnusedMappedSuperclasses(); + if ( !unusedMappedSuperclasses.isEmpty() ) { + for ( MappedSuperclass mappedSuperclass : unusedMappedSuperclasses ) { + log.unusedMappedSuperclass( mappedSuperclass.getMappedClass().getName() ); + locateOrBuildMappedSuperclassType( mappedSuperclass, context, typeConfiguration ); + } + } + } + + private MappedSuperclassDomainType locateOrBuildMappedSuperclassType( + MappedSuperclass mappedSuperclass, + MetadataContext context, + TypeConfiguration typeConfiguration) { + MappedSuperclassDomainType mappedSuperclassType = context.locateMappedSuperclassType( mappedSuperclass ); + if ( mappedSuperclassType == null ) { + mappedSuperclassType = buildMappedSuperclassType( mappedSuperclass, context, typeConfiguration ); + } + return mappedSuperclassType; + } + + @SuppressWarnings("unchecked") + private MappedSuperclassTypeImpl buildMappedSuperclassType( + MappedSuperclass mappedSuperclass, + MetadataContext context, + TypeConfiguration typeConfiguration) { + final MappedSuperclass superMappedSuperclass = mappedSuperclass.getSuperMappedSuperclass(); + IdentifiableDomainType superType = superMappedSuperclass == null + ? null + : locateOrBuildMappedSuperclassType( superMappedSuperclass, context, typeConfiguration ); + //no mappedSuperclass, check for a super entity + if ( superType == null ) { + final PersistentClass superPersistentClass = mappedSuperclass.getSuperPersistentClass(); + superType = superPersistentClass == null + ? null + : locateOrBuildEntityType( superPersistentClass, context, typeConfiguration ); + } + final JavaTypeDescriptor javaTypeDescriptor = context.getTypeConfiguration() + .getJavaTypeDescriptorRegistry() + .getDescriptor( mappedSuperclass.getMappedClass() ); + final MappedSuperclassTypeImpl mappedSuperclassType = new MappedSuperclassTypeImpl( + javaTypeDescriptor, + mappedSuperclass, + superType, + this + ); + + context.registerMappedSuperclassType( mappedSuperclass, mappedSuperclassType ); + return mappedSuperclassType; + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappedSuperclassTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappedSuperclassTypeImpl.java index 7a13e9fea7..9df376c85f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappedSuperclassTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappedSuperclassTypeImpl.java @@ -11,9 +11,9 @@ import org.hibernate.mapping.MappedSuperclass; import org.hibernate.metamodel.model.domain.AbstractIdentifiableType; import org.hibernate.metamodel.model.domain.IdentifiableDomainType; +import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.metamodel.model.domain.MappedSuperclassDomainType; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; -import org.hibernate.type.spi.TypeConfiguration; /** * @author Emmanuel Bernard @@ -24,7 +24,7 @@ public MappedSuperclassTypeImpl( JavaTypeDescriptor javaTypeDescriptor, MappedSuperclass mappedSuperclass, IdentifiableDomainType superType, - TypeConfiguration typeConfiguration) { + JpaMetamodel jpaMetamodel) { super( javaTypeDescriptor.getJavaType().getName(), javaTypeDescriptor, @@ -32,7 +32,7 @@ public MappedSuperclassTypeImpl( mappedSuperclass.getDeclaredIdentifierMapper() != null || ( superType != null && superType.hasIdClass() ), mappedSuperclass.hasIdentifierProperty(), mappedSuperclass.isVersioned(), - typeConfiguration + jpaMetamodel ); } diff --git a/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java b/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java index cf523ed326..30d846c4a1 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/CollectionType.java @@ -45,6 +45,7 @@ import org.hibernate.pretty.MessageHelper; import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.LazyInitializer; +import org.hibernate.sql.results.spi.LoadingCollectionEntry; import org.jboss.logging.Logger; @@ -809,9 +810,13 @@ public Object getCollection(Serializable key, SharedSessionContractImplementor s final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); final CollectionKey collectionKey = new CollectionKey( persister, key ); + PersistentCollection collection = null; + // check if collection is currently being loaded - PersistentCollection collection = persistenceContext.getLoadContexts() - .locateLoadingCollection( persister, collectionKey ); + final LoadingCollectionEntry loadingCollectionEntry = persistenceContext.getLoadContexts().findLoadingCollectionEntry( collectionKey ); + if ( loadingCollectionEntry != null ) { + collection = loadingCollectionEntry.getCollectionInstance(); + } if ( collection == null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/type/EnumType.java b/hibernate-core/src/main/java/org/hibernate/type/EnumType.java index 12558d2e7b..f6f46623ac 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/EnumType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/EnumType.java @@ -19,6 +19,7 @@ import org.hibernate.AssertionFailure; import org.hibernate.HibernateException; +import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.annotations.Nationalized; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; @@ -303,8 +304,9 @@ public int hashCode(Object x) throws HibernateException { @Override public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws SQLException { - verifyConfigured(); - return enumValueConverter.readValue( rs, names[0], session ); + throw new NotYetImplementedFor6Exception( getClass() ); +// verifyConfigured(); +// return enumValueConverter.readValue( rs, names[0], session ); } private void verifyConfigured() { @@ -315,8 +317,9 @@ private void verifyConfigured() { @Override public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { - verifyConfigured(); - enumValueConverter.writeValue( st, (Enum) value, index, session ); + throw new NotYetImplementedFor6Exception( getClass() ); +// verifyConfigured(); +// enumValueConverter.writeValue( st, (Enum) value, index, session ); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java index 477f278dd6..97e0bfc916 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/metadata/MetadataTest.java @@ -28,9 +28,9 @@ import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; -import org.hibernate.metamodel.internal.JpaMetaModelPopulationSetting; import org.hibernate.metamodel.internal.RuntimeModelCreationProcess; +import org.hibernate.testing.boot.BootstrapContextImpl; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -96,9 +96,10 @@ public void testBuildingMetamodelWithParameterizedCollection() { SessionFactoryImplementor sfi = (SessionFactoryImplementor) metadata.buildSessionFactory(); new RuntimeModelCreationProcess( + BootstrapContextImpl.INSTANCE, sfi, ( (MetadataImplementor) metadata ).getTypeConfiguration() - ).create( (MetadataImplementor) metadata, JpaMetaModelPopulationSetting.IGNORE_UNSUPPORTED ); + ).create( (MetadataImplementor) metadata ); sfi.close(); }