From 2b89553db5081fe4e55b7b34d636d0ea2acf71c5 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Mon, 8 Jun 2015 14:23:43 -0500 Subject: [PATCH] HHH-9855 - Ignore non-entity classes listed as "managed classes" in persistence.xml --- ...AnnotationMetadataSourceProcessorImpl.java | 41 ++++++++++--------- .../entitynonentity/EntityNonEntityTest.java | 2 + 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/AnnotationMetadataSourceProcessorImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/AnnotationMetadataSourceProcessorImpl.java index f06f481e57..7cd0257d3e 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/AnnotationMetadataSourceProcessorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/AnnotationMetadataSourceProcessorImpl.java @@ -32,6 +32,7 @@ import org.jboss.logging.Logger; import javax.persistence.AttributeConverter; import javax.persistence.Converter; import javax.persistence.Entity; +import javax.persistence.MappedSuperclass; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; @@ -97,28 +98,28 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc final ClassLoaderService cls = rootMetadataBuildingContext.getBuildingOptions().getServiceRegistry().getService( ClassLoaderService.class ); for ( String className : sources.getAnnotatedClassNames() ) { - final Class clazz = cls.classForName( className ); - final XClass xClass = reflectionManager.toXClass( clazz ); - // categorize it, based on assumption it is either an AttributeConverter or an entity - if ( xClass.isAnnotationPresent( Converter.class ) ) { - //noinspection unchecked - attributeConverterManager.addAttributeConverter( clazz ); - } - else { - xClasses.add( xClass ); - } + final Class annotatedClass = cls.classForName( className ); + categorizeAnnotatedClass( annotatedClass, attributeConverterManager ); } - for ( Class annotateClass : sources.getAnnotatedClasses() ) { - final XClass xClass = reflectionManager.toXClass( annotateClass ); - // categorize it, based on assumption it is either an AttributeConverter or an entity - if ( xClass.isAnnotationPresent( Converter.class ) ) { - //noinspection unchecked - attributeConverterManager.addAttributeConverter( annotateClass ); - } - else { - xClasses.add( xClass ); - } + for ( Class annotatedClass : sources.getAnnotatedClasses() ) { + categorizeAnnotatedClass( annotatedClass, attributeConverterManager ); + } + } + + private void categorizeAnnotatedClass(Class annotatedClass, AttributeConverterManager attributeConverterManager) { + final XClass xClass = reflectionManager.toXClass( annotatedClass ); + // categorize it, based on assumption it does not fall into multiple categories + if ( xClass.isAnnotationPresent( Converter.class ) ) { + //noinspection unchecked + attributeConverterManager.addAttributeConverter( annotatedClass ); + } + else if ( xClass.isAnnotationPresent( Entity.class ) + || xClass.isAnnotationPresent( MappedSuperclass.class ) ) { + xClasses.add( xClass ); + } + else { + log.debugf( "Encountered a non-categorized annotated class [%s]; ignoring", annotatedClass.getName() ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/entitynonentity/EntityNonEntityTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/entitynonentity/EntityNonEntityTest.java index 59d3423cd9..cee73e18df 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/entitynonentity/EntityNonEntityTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/entitynonentity/EntityNonEntityTest.java @@ -50,6 +50,8 @@ public class EntityNonEntityTest extends BaseCoreFunctionalTestCase { return new Class[]{ Phone.class, Voice.class, + // Adding Cellular here is a test for HHH-9855 + Cellular.class, GSM.class }; }