Skip to content

Commit

Permalink
HHH-8962 : Fix compile failures and remove @FailureExpectedWithNewMet…
Browse files Browse the repository at this point in the history
…amodel from passing test
  • Loading branch information
gbadner committed Feb 17, 2014
1 parent e84ed19 commit 97ee747
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 30 deletions.
Expand Up @@ -331,7 +331,7 @@ private Class<? extends Interceptor> loadSessionInterceptorClass(Object value, S
private List<String> collectNamesOfClassesToEnhance(MetadataImplementor metadata) {
final List<String> entityClassNames = new ArrayList<String>();
for ( EntityBinding eb : metadata.getEntityBindings() ) {
entityClassNames.add( eb.getEntity().getClassReference().getName() );
entityClassNames.add( eb.getEntity().getDescriptor().getName().fullName() );
}
return entityClassNames;
}
Expand Down
Expand Up @@ -65,7 +65,9 @@ public void processCallbacksForEntity(Object entityObject, CallbackRegistryImpl
if ( entityBinding.getHierarchyDetails().getEntityMode() != EntityMode.POJO ) {
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 ) {
callbackRegistry.addEntityCallbacks(
entityClass,
Expand Down
Expand Up @@ -48,6 +48,7 @@
import org.hibernate.jpa.internal.metamodel.MappedSuperclassTypeImpl;
import org.hibernate.jpa.internal.metamodel.MetamodelImpl;
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.BasicAttributeBinding;
import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding;
Expand Down Expand Up @@ -79,6 +80,8 @@ public class MetamodelBuilder {
MetamodelBuilder.class.getName()
);
private final SessionFactoryImplementor sessionFactory;
private final ClassLoaderService classLoaderService;


// these maps eventually make up the JPA Metamodel
private final Map<Class<?>,EntityTypeImpl<?>> entityTypeMap = new HashMap<Class<?>, EntityTypeImpl<?>>();
Expand Down Expand Up @@ -106,6 +109,7 @@ public static MetamodelImpl oneShot(

public MetamodelBuilder(SessionFactoryImplementor sessionFactory, JpaMetaModelPopulationSetting populationSetting) {
this.sessionFactory = sessionFactory;
this.classLoaderService = sessionFactory.getServiceRegistry().getService( ClassLoaderService.class );
this.populationSetting = populationSetting;
this.attributeBuilder = new AttributeBuilder( new AttributeBuilderContext() );
}
Expand Down Expand Up @@ -153,52 +157,58 @@ private EntityTypeImpl buildEntityType(EntityBinding entityBinding) {
* </ol>
* 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
* 2 use cases described above.
*
* @return The super type.
*/
private AbstractIdentifiableType locateOrBuildSuperType(Hierarchical superDescriptor, EntityBinding entityBinding) {
if ( superDescriptor == null ) {
private AbstractIdentifiableType locateOrBuildSuperType(Hierarchical hierarchical, EntityBinding entityBinding) {
if ( hierarchical == null ) {
return null;
}

// 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...
final EntityBinding superBinding = entityBinding.getSuperEntityBinding();
if ( superBinding == null ) {
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" );
}
return locateOrBuildEntityType( superBinding );
}
else if ( Superclass.class.isInstance( superDescriptor ) ) {
return locateOrBuildMappedSuperclassType( (Superclass) superDescriptor, entityBinding );
else if ( Superclass.class.isInstance( hierarchical ) ) {
return locateOrBuildMappedSuperclassType( (Superclass) hierarchical, entityBinding );
}
else {
throw new IllegalStateException(
"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) {
MappedSuperclassTypeImpl mappedSuperclassType = mappedSuperclassTypeMap.get( superDescriptor.getClassReference().getResolvedClass() );
private MappedSuperclassTypeImpl locateOrBuildMappedSuperclassType(Superclass superclass, EntityBinding entityBinding) {
MappedSuperclassTypeImpl mappedSuperclassType = mappedSuperclassTypeMap.get(
loadClass( superclass.getDescriptor() )
);
if ( mappedSuperclassType == null ) {
mappedSuperclassType = buildMappedSuperclassType( superDescriptor, entityBinding );
mappedSuperclassType = buildMappedSuperclassType( superclass, entityBinding );
}
return mappedSuperclassType;
}

private Class<?> loadClass(JavaTypeDescriptor descriptor) {
return classLoaderService.classForName( descriptor.getName().fullName() );
}

@SuppressWarnings("unchecked")
private MappedSuperclassTypeImpl buildMappedSuperclassType(Superclass superDescriptor, EntityBinding entityBinding) {
final Class javaType = superDescriptor.getClassReference().getResolvedClass();
final AbstractIdentifiableType superSuperType = locateOrBuildSuperType( superDescriptor, entityBinding );
private MappedSuperclassTypeImpl buildMappedSuperclassType(Superclass superclass, EntityBinding entityBinding) {
final Class javaType = loadClass( superclass.getDescriptor() );
final AbstractIdentifiableType superSuperType = locateOrBuildSuperType( superclass, entityBinding );

MappedSuperclassTypeImpl mappedSuperclassType = new MappedSuperclassTypeImpl(
javaType,
Expand Down Expand Up @@ -256,30 +266,30 @@ private void processHierarchy(EntityBinding entityBinding) {
/**
* 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
*/
private void processType(Hierarchical descriptor, EntityBinding entityBinding) {
if ( descriptor == null ) {
private void processType(Hierarchical hierarchical, EntityBinding entityBinding) {
if ( hierarchical == null ) {
return;
}

if ( alreadyProcessed.contains( descriptor ) ) {
if ( alreadyProcessed.contains( hierarchical ) ) {
return;
}
alreadyProcessed.add( descriptor );
alreadyProcessed.add( hierarchical );

// perform a depth-first traversal of the super types...
processSuperType( descriptor, entityBinding );
processSuperType( hierarchical, entityBinding );

final AbstractIdentifiableType jpaDescriptor = Entity.class.isInstance( descriptor )
? entityTypeByNameMap.get( descriptor.getName() )
: mappedSuperclassTypeMap.get( descriptor.getClassReference() );
final AbstractIdentifiableType jpaDescriptor = Entity.class.isInstance( hierarchical )
? entityTypeByNameMap.get( hierarchical.getName() )
: mappedSuperclassTypeMap.get( loadClass( hierarchical.getDescriptor() ) );
if ( jpaDescriptor == null && entityBinding.getHierarchyDetails().getEntityMode() != EntityMode.POJO ) {
return;
}
applyIdMetadata( descriptor, entityBinding.getHierarchyDetails(), jpaDescriptor );
applyVersionAttribute( descriptor, entityBinding.getHierarchyDetails(), jpaDescriptor );
applyIdMetadata( hierarchical, entityBinding.getHierarchyDetails(), jpaDescriptor );
applyVersionAttribute( hierarchical, entityBinding.getHierarchyDetails(), jpaDescriptor );

for ( AttributeBinding attributeBinding : entityBinding.attributeBindings() ) {
if ( entityBinding.getHierarchyDetails().getEntityIdentifier().isIdentifierAttributeBinding( attributeBinding ) ) {
Expand Down
Expand Up @@ -57,12 +57,9 @@
import org.hibernate.loader.plan.spi.QuerySpace;
import org.hibernate.persister.entity.EntityPersister;

import org.hibernate.testing.FailureExpectedWithNewMetamodel;

/**
* @author Strong Liu <stliu@hibernate.org>
*/
@FailureExpectedWithNewMetamodel( message = "Caused by: java.lang.IllegalArgumentException: resolvedHibernateType must be non-null." )
public class EntityGraphLoadPlanBuilderTest extends BaseEntityManagerFunctionalTestCase {
@Override
protected Class<?>[] getAnnotatedClasses() {
Expand Down

0 comments on commit 97ee747

Please sign in to comment.