HHH-8962 : Fix compile failures and remove @FailureExpectedWithNewMetamodel from passing test

This commit is contained in:
Gail Badner 2014-02-17 12:52:19 -08:00
parent e84ed199e3
commit 97ee747907
4 changed files with 39 additions and 30 deletions

View File

@ -331,7 +331,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
private List<String> collectNamesOfClassesToEnhance(MetadataImplementor metadata) { private List<String> collectNamesOfClassesToEnhance(MetadataImplementor metadata) {
final List<String> entityClassNames = new ArrayList<String>(); final List<String> entityClassNames = new ArrayList<String>();
for ( EntityBinding eb : metadata.getEntityBindings() ) { for ( EntityBinding eb : metadata.getEntityBindings() ) {
entityClassNames.add( eb.getEntity().getClassReference().getName() ); entityClassNames.add( eb.getEntity().getDescriptor().getName().fullName() );
} }
return entityClassNames; return entityClassNames;
} }

View File

@ -65,7 +65,9 @@ public class CallbackProcessorImpl implements CallbackProcessor {
if ( entityBinding.getHierarchyDetails().getEntityMode() != EntityMode.POJO ) { if ( entityBinding.getHierarchyDetails().getEntityMode() != EntityMode.POJO ) {
return; return;
} }
final Class entityClass = entityBinding.getEntity().getClassReference().getResolvedClass(); final Class entityClass = classLoaderService.classForName(
entityBinding.getEntity().getDescriptor().getName().fullName()
);
for ( final Class annotationClass : CALLBACK_ANNOTATION_CLASSES ) { for ( final Class annotationClass : CALLBACK_ANNOTATION_CLASSES ) {
callbackRegistry.addEntityCallbacks( callbackRegistry.addEntityCallbacks(
entityClass, entityClass,

View File

@ -48,6 +48,7 @@ import org.hibernate.jpa.internal.metamodel.EntityTypeImpl;
import org.hibernate.jpa.internal.metamodel.MappedSuperclassTypeImpl; import org.hibernate.jpa.internal.metamodel.MappedSuperclassTypeImpl;
import org.hibernate.jpa.internal.metamodel.MetamodelImpl; import org.hibernate.jpa.internal.metamodel.MetamodelImpl;
import org.hibernate.metamodel.Metadata; import org.hibernate.metamodel.Metadata;
import org.hibernate.metamodel.reflite.spi.JavaTypeDescriptor;
import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBinding;
import org.hibernate.metamodel.spi.binding.BasicAttributeBinding; import org.hibernate.metamodel.spi.binding.BasicAttributeBinding;
import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding;
@ -79,6 +80,8 @@ public class MetamodelBuilder {
MetamodelBuilder.class.getName() MetamodelBuilder.class.getName()
); );
private final SessionFactoryImplementor sessionFactory; private final SessionFactoryImplementor sessionFactory;
private final ClassLoaderService classLoaderService;
// these maps eventually make up the JPA Metamodel // these maps eventually make up the JPA Metamodel
private final Map<Class<?>,EntityTypeImpl<?>> entityTypeMap = new HashMap<Class<?>, EntityTypeImpl<?>>(); private final Map<Class<?>,EntityTypeImpl<?>> entityTypeMap = new HashMap<Class<?>, EntityTypeImpl<?>>();
@ -106,6 +109,7 @@ public class MetamodelBuilder {
public MetamodelBuilder(SessionFactoryImplementor sessionFactory, JpaMetaModelPopulationSetting populationSetting) { public MetamodelBuilder(SessionFactoryImplementor sessionFactory, JpaMetaModelPopulationSetting populationSetting) {
this.sessionFactory = sessionFactory; this.sessionFactory = sessionFactory;
this.classLoaderService = sessionFactory.getServiceRegistry().getService( ClassLoaderService.class );
this.populationSetting = populationSetting; this.populationSetting = populationSetting;
this.attributeBuilder = new AttributeBuilder( new AttributeBuilderContext() ); this.attributeBuilder = new AttributeBuilder( new AttributeBuilderContext() );
} }
@ -153,52 +157,58 @@ public class MetamodelBuilder {
* </ol> * </ol>
* Make sure changes fit both uses * Make sure changes fit both uses
* *
* @param superDescriptor Hibernate metamodel descriptor of the super class * @param hierarchical Hibernate metamodel descriptor of the super class
* @param entityBinding The Hibernate metamodel entity binding; could be describing different class between the * @param entityBinding The Hibernate metamodel entity binding; could be describing different class between the
* 2 use cases described above. * 2 use cases described above.
* *
* @return The super type. * @return The super type.
*/ */
private AbstractIdentifiableType locateOrBuildSuperType(Hierarchical superDescriptor, EntityBinding entityBinding) { private AbstractIdentifiableType locateOrBuildSuperType(Hierarchical hierarchical, EntityBinding entityBinding) {
if ( superDescriptor == null ) { if ( hierarchical == null ) {
return null; return null;
} }
// the super type here could be either a "mapped superclass" or an entity // the super type here could be either a "mapped superclass" or an entity
if ( Entity.class.isInstance( superDescriptor ) ) { if ( Entity.class.isInstance( hierarchical ) ) {
// make sure super entity binding points to same... // make sure super entity binding points to same...
final EntityBinding superBinding = entityBinding.getSuperEntityBinding(); final EntityBinding superBinding = entityBinding.getSuperEntityBinding();
if ( superBinding == null ) { if ( superBinding == null ) {
throw new IllegalStateException( "EntityBinding with super class of Entity type did not specify super entity binding" ); throw new IllegalStateException( "EntityBinding with super class of Entity type did not specify super entity binding" );
} }
if ( superBinding.getEntity() != superDescriptor ) { if ( superBinding.getEntity() != hierarchical ) {
throw new IllegalStateException( "Super entity binding and descriptor referenced different descriptors" ); throw new IllegalStateException( "Super entity binding and descriptor referenced different descriptors" );
} }
return locateOrBuildEntityType( superBinding ); return locateOrBuildEntityType( superBinding );
} }
else if ( Superclass.class.isInstance( superDescriptor ) ) { else if ( Superclass.class.isInstance( hierarchical ) ) {
return locateOrBuildMappedSuperclassType( (Superclass) superDescriptor, entityBinding ); return locateOrBuildMappedSuperclassType( (Superclass) hierarchical, entityBinding );
} }
else { else {
throw new IllegalStateException( throw new IllegalStateException(
"Unexpected type for entity super descriptor; expecting Entity or Superclass, found [" "Unexpected type for entity super descriptor; expecting Entity or Superclass, found ["
+ superDescriptor.getClassReference().getName() + "]" + hierarchical.getDescriptor().getName().fullName() + "]"
); );
} }
} }
private MappedSuperclassTypeImpl locateOrBuildMappedSuperclassType(Superclass superDescriptor, EntityBinding entityBinding) { private MappedSuperclassTypeImpl locateOrBuildMappedSuperclassType(Superclass superclass, EntityBinding entityBinding) {
MappedSuperclassTypeImpl mappedSuperclassType = mappedSuperclassTypeMap.get( superDescriptor.getClassReference().getResolvedClass() ); MappedSuperclassTypeImpl mappedSuperclassType = mappedSuperclassTypeMap.get(
loadClass( superclass.getDescriptor() )
);
if ( mappedSuperclassType == null ) { if ( mappedSuperclassType == null ) {
mappedSuperclassType = buildMappedSuperclassType( superDescriptor, entityBinding ); mappedSuperclassType = buildMappedSuperclassType( superclass, entityBinding );
} }
return mappedSuperclassType; return mappedSuperclassType;
} }
private Class<?> loadClass(JavaTypeDescriptor descriptor) {
return classLoaderService.classForName( descriptor.getName().fullName() );
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private MappedSuperclassTypeImpl buildMappedSuperclassType(Superclass superDescriptor, EntityBinding entityBinding) { private MappedSuperclassTypeImpl buildMappedSuperclassType(Superclass superclass, EntityBinding entityBinding) {
final Class javaType = superDescriptor.getClassReference().getResolvedClass(); final Class javaType = loadClass( superclass.getDescriptor() );
final AbstractIdentifiableType superSuperType = locateOrBuildSuperType( superDescriptor, entityBinding ); final AbstractIdentifiableType superSuperType = locateOrBuildSuperType( superclass, entityBinding );
MappedSuperclassTypeImpl mappedSuperclassType = new MappedSuperclassTypeImpl( MappedSuperclassTypeImpl mappedSuperclassType = new MappedSuperclassTypeImpl(
javaType, javaType,
@ -256,30 +266,30 @@ public class MetamodelBuilder {
/** /**
* Performs a depth-first traversal of the super types... * Performs a depth-first traversal of the super types...
* *
* @param descriptor The type descriptor to process * @param hierarchical The type descriptor to process
* @param entityBinding * @param entityBinding
*/ */
private void processType(Hierarchical descriptor, EntityBinding entityBinding) { private void processType(Hierarchical hierarchical, EntityBinding entityBinding) {
if ( descriptor == null ) { if ( hierarchical == null ) {
return; return;
} }
if ( alreadyProcessed.contains( descriptor ) ) { if ( alreadyProcessed.contains( hierarchical ) ) {
return; return;
} }
alreadyProcessed.add( descriptor ); alreadyProcessed.add( hierarchical );
// perform a depth-first traversal of the super types... // perform a depth-first traversal of the super types...
processSuperType( descriptor, entityBinding ); processSuperType( hierarchical, entityBinding );
final AbstractIdentifiableType jpaDescriptor = Entity.class.isInstance( descriptor ) final AbstractIdentifiableType jpaDescriptor = Entity.class.isInstance( hierarchical )
? entityTypeByNameMap.get( descriptor.getName() ) ? entityTypeByNameMap.get( hierarchical.getName() )
: mappedSuperclassTypeMap.get( descriptor.getClassReference() ); : mappedSuperclassTypeMap.get( loadClass( hierarchical.getDescriptor() ) );
if ( jpaDescriptor == null && entityBinding.getHierarchyDetails().getEntityMode() != EntityMode.POJO ) { if ( jpaDescriptor == null && entityBinding.getHierarchyDetails().getEntityMode() != EntityMode.POJO ) {
return; return;
} }
applyIdMetadata( descriptor, entityBinding.getHierarchyDetails(), jpaDescriptor ); applyIdMetadata( hierarchical, entityBinding.getHierarchyDetails(), jpaDescriptor );
applyVersionAttribute( descriptor, entityBinding.getHierarchyDetails(), jpaDescriptor ); applyVersionAttribute( hierarchical, entityBinding.getHierarchyDetails(), jpaDescriptor );
for ( AttributeBinding attributeBinding : entityBinding.attributeBindings() ) { for ( AttributeBinding attributeBinding : entityBinding.attributeBindings() ) {
if ( entityBinding.getHierarchyDetails().getEntityIdentifier().isIdentifierAttributeBinding( attributeBinding ) ) { if ( entityBinding.getHierarchyDetails().getEntityIdentifier().isIdentifierAttributeBinding( attributeBinding ) ) {

View File

@ -57,12 +57,9 @@ import org.hibernate.loader.plan.spi.LoadPlan;
import org.hibernate.loader.plan.spi.QuerySpace; import org.hibernate.loader.plan.spi.QuerySpace;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
/** /**
* @author Strong Liu <stliu@hibernate.org> * @author Strong Liu <stliu@hibernate.org>
*/ */
@FailureExpectedWithNewMetamodel( message = "Caused by: java.lang.IllegalArgumentException: resolvedHibernateType must be non-null." )
public class EntityGraphLoadPlanBuilderTest extends BaseEntityManagerFunctionalTestCase { public class EntityGraphLoadPlanBuilderTest extends BaseEntityManagerFunctionalTestCase {
@Override @Override
protected Class<?>[] getAnnotatedClasses() { protected Class<?>[] getAnnotatedClasses() {