mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-18 17:15:02 +00:00
HHH-7696 Support multiple @AttributeOverride annotations
This commit is contained in:
parent
7f1dbc2ef0
commit
9ed8ac16aa
@ -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<String, AttributeOverride> findAttributeOverrides() {
|
||||
Map<String, AttributeOverride> attributeOverrideList = new HashMap<String, AttributeOverride>();
|
||||
Map<String, AttributeOverride> attributeOverrideList
|
||||
= new HashMap<String, AttributeOverride>();
|
||||
|
||||
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 );
|
||||
// Add all instances of @AttributeOverride
|
||||
List<AnnotationInstance> 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<AnnotationInstance> 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;
|
||||
|
@ -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<String, Object> DEFAULT_VALUES_BY_ELEMENT = new HashMap<String, Object>();
|
||||
@ -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<AnnotationInstance> getAnnotations(
|
||||
ClassInfo classInfo, DotName annotationName ) {
|
||||
return classInfo.annotations().get( annotationName );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param classInfo the class info from which to retrieve the annotation instance
|
||||
|
@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user