diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/entity/ConfiguredClass.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/entity/ConfiguredClass.java index 044242d92584..52b107d9da43 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/entity/ConfiguredClass.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/entity/ConfiguredClass.java @@ -72,6 +72,7 @@ * Base class for a configured entity, mapped super class or embeddable * * @author Hardy Ferentschik + * @author Brett Meyer */ public class ConfiguredClass { private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, AssertionFailure.class.getName()); @@ -704,28 +705,36 @@ private void findTransientFieldAndMethodNames() { } private Map findAttributeOverrides() { - Map attributeOverrideList = new HashMap(); - - AnnotationInstance attributeOverrideAnnotation = JandexHelper.getSingleAnnotation( - classInfo, - JPADotNames.ATTRIBUTE_OVERRIDE - ); - if ( attributeOverrideAnnotation != null ) { - String prefix = createPathPrefix( attributeOverrideAnnotation.target() ); - AttributeOverride override = new AttributeOverride( prefix, attributeOverrideAnnotation ); - attributeOverrideList.put( override.getAttributePath(), override ); + Map attributeOverrideList + = new HashMap(); + + // Add all instances of @AttributeOverride + List attributeOverrideAnnotations = JandexHelper + .getAnnotations(classInfo, JPADotNames.ATTRIBUTE_OVERRIDE ); + if ( attributeOverrideAnnotations != null ) { + for ( AnnotationInstance annotation : attributeOverrideAnnotations ) { + AttributeOverride override = new AttributeOverride( + createPathPrefix( annotation.target() ), annotation ); + attributeOverrideList.put( + override.getAttributePath(), override ); + } } - AnnotationInstance attributeOverridesAnnotation = JandexHelper.getSingleAnnotation( - classInfo, - JPADotNames.ATTRIBUTE_OVERRIDES - ); - if ( attributeOverridesAnnotation != null ) { - AnnotationInstance[] annotationInstances = attributeOverridesAnnotation.value().asNestedArray(); - for ( AnnotationInstance annotationInstance : annotationInstances ) { - String prefix = createPathPrefix( attributeOverridesAnnotation.target() ); - AttributeOverride override = new AttributeOverride( prefix, annotationInstance ); - attributeOverrideList.put( override.getAttributePath(), override ); + // Add all instances of @AttributeOverrides children + List attributeOverridesAnnotations = JandexHelper + .getAnnotations(classInfo, JPADotNames.ATTRIBUTE_OVERRIDES); + if ( attributeOverridesAnnotations != null ) { + for ( AnnotationInstance attributeOverridesAnnotation : attributeOverridesAnnotations ) { + AnnotationInstance[] annotationInstances + = attributeOverridesAnnotation.value().asNestedArray(); + for ( AnnotationInstance annotation : annotationInstances ) { + AttributeOverride override = new AttributeOverride( + createPathPrefix( + attributeOverridesAnnotation.target() ), + annotation ); + attributeOverrideList.put( + override.getAttributePath(), override ); + } } } return attributeOverrideList; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JandexHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JandexHelper.java index 4c82b10699b7..821e9ae88ee6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JandexHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/source/annotations/util/JandexHelper.java @@ -52,6 +52,7 @@ * Utility methods for working with the jandex annotation index. * * @author Hardy Ferentschik + * @author Brett Meyer */ public class JandexHelper { private static final Map DEFAULT_VALUES_BY_ELEMENT = new HashMap(); @@ -176,6 +177,17 @@ else if ( methodName.startsWith( "get" ) ) { return propertyName; } } + + /** + * @param classInfo the class info from which to retrieve the annotation instance + * @param annotationName the annotation to retrieve from the class info + * + * @return the list of annotations specified in the class + */ + public static List getAnnotations( + ClassInfo classInfo, DotName annotationName ) { + return classInfo.annotations().get( annotationName ); + } /** * @param classInfo the class info from which to retrieve the annotation instance diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddedTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddedTest.java index 53ad741bfd2f..d750c7da2e09 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddedTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddedTest.java @@ -23,13 +23,15 @@ */ package org.hibernate.test.annotations.embedded; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Set; -import org.junit.Test; - import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.Transaction; @@ -38,10 +40,7 @@ import org.hibernate.test.util.SchemaUtil; import org.hibernate.testing.FailureExpectedWithNewMetamodel; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import org.junit.Test; /** * @author Emmanuel Bernard @@ -537,7 +536,8 @@ protected Class[] getAnnotatedClasses() { Country.class, InternetFavorites.class, FixedLeg.class, - FloatLeg.class + FloatLeg.class, + Swap.class }; } }