From b0a9ced9d83d40c3cb8b0145484bbdb8ac6d4777 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Mon, 6 Oct 2014 14:39:16 +0100 Subject: [PATCH] HHH-8895 Fix EntitySourceImpl class --- .../annotations/EntitySourceImpl.java | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/EntitySourceImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/EntitySourceImpl.java index 8d3f2e1d76..92556fb6b2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/EntitySourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/internal/annotations/EntitySourceImpl.java @@ -43,6 +43,7 @@ import org.hibernate.metamodel.source.internal.annotations.attribute.PrimaryKeyJ import org.hibernate.metamodel.source.internal.annotations.entity.EntityBindingContext; import org.hibernate.metamodel.source.internal.annotations.entity.EntityTypeMetadata; import org.hibernate.metamodel.source.internal.annotations.entity.ManagedTypeMetadata; +import org.hibernate.metamodel.source.internal.annotations.entity.MappedSuperclassTypeMetadata; import org.hibernate.metamodel.source.internal.annotations.util.HibernateDotNames; import org.hibernate.metamodel.source.internal.annotations.util.JPADotNames; import org.hibernate.metamodel.source.spi.ConstraintSource; @@ -59,6 +60,7 @@ import org.hibernate.xml.spi.Origin; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; +import org.jboss.jandex.DotName; /** * Common base class for adapting Entity classes to the metamodel source structure. @@ -154,10 +156,9 @@ public abstract class EntitySourceImpl extends IdentifiableTypeSourceAdapter imp } private FilterSource[] buildFilterSources() { - AnnotationInstance filtersAnnotation = getEntityClass().getJavaTypeDescriptor().findTypeAnnotation( - HibernateDotNames.FILTERS - ); + AnnotationInstance filtersAnnotation = findAnnotationInstance( HibernateDotNames.FILTERS ); List filterSourceList = new ArrayList(); + if ( filtersAnnotation != null ) { AnnotationInstance[] annotationInstances = filtersAnnotation.value().asNestedArray(); for ( AnnotationInstance filterAnnotation : annotationInstances ) { @@ -167,9 +168,8 @@ public abstract class EntitySourceImpl extends IdentifiableTypeSourceAdapter imp } - AnnotationInstance filterAnnotation = getEntityClass().getJavaTypeDescriptor().findTypeAnnotation( - HibernateDotNames.FILTER - ); + AnnotationInstance filterAnnotation = findAnnotationInstance( HibernateDotNames.FILTER ); + if ( filterAnnotation != null ) { FilterSource filterSource = new FilterSourceImpl( filterAnnotation ); filterSourceList.add( filterSource ); @@ -182,6 +182,25 @@ public abstract class EntitySourceImpl extends IdentifiableTypeSourceAdapter imp } } + /** + * Get the annotation of the named type, if one, defined on this type or any of its MappedSuperclass super-types + * (only walk up MappedSuperclass hierarchy). + */ + private AnnotationInstance findAnnotationInstance(DotName annotationType) { + IdentifiableTypeSourceAdapter superType = this.getSuperType(); + + AnnotationInstance result; + if ( superType != null && superType.getManagedTypeMetadata() instanceof MappedSuperclassTypeMetadata ) { + // walk up super-type hierarchy + result = getEntityClass().getJavaTypeDescriptor().findTypeAnnotation( annotationType ); + } + else { + // DO NOT walk up super-type hierarchy + result = getEntityClass().getJavaTypeDescriptor().findLocalTypeAnnotation( annotationType ); + } + return result; + } + protected boolean isRootEntity() { return false; }