From 94ad371bf36013222150f2919bbb9f94d9a49f2b Mon Sep 17 00:00:00 2001 From: Etienne Miret Date: Sun, 8 Feb 2015 23:01:25 +0100 Subject: [PATCH] HHH-9247 Attribute "name" of named-attribute-node maps to "value" of annotation. --- .../JPAOverriddenAnnotationReader.java | 38 +++++++++++++++++-- .../entityGraph/OrmXmlParseTest.java | 4 +- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/reflection/JPAOverriddenAnnotationReader.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/reflection/JPAOverriddenAnnotationReader.java index bea60db6c2..b9c1d123af 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/reflection/JPAOverriddenAnnotationReader.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/reflection/JPAOverriddenAnnotationReader.java @@ -1949,7 +1949,7 @@ public class JPAOverriddenAnnotationReader implements AnnotationReader { List annNamedAttributeNodes = new ArrayList( ); for(Element namedAttributeNode : namedAttributeNodes){ AnnotationDescriptor annNamedAttributeNode = new AnnotationDescriptor( NamedAttributeNode.class ); - copyStringAttribute( annNamedAttributeNode, namedAttributeNode, "value", true ); + copyStringAttribute( annNamedAttributeNode, namedAttributeNode, "value", "name", true ); copyStringAttribute( annNamedAttributeNode, namedAttributeNode, "subgraph", false ); copyStringAttribute( annNamedAttributeNode, namedAttributeNode, "key-subgraph", false ); annNamedAttributeNodes.add( (NamedAttributeNode) AnnotationFactory.create( annNamedAttributeNode ) ); @@ -2903,12 +2903,42 @@ public class JPAOverriddenAnnotationReader implements AnnotationReader { return pkJoinColumns; } + /** + * Copy a string attribute from an XML element to an annotation descriptor. The name of the annotation attribute is + * computed from the name of the XML attribute by {@link #getJavaAttributeNameFromXMLOne(String)}. + * + * @param annotation annotation descriptor where to copy to the attribute. + * @param element XML element from where to copy the attribute. + * @param attributeName name of the XML attribute to copy. + * @param mandatory whether the attribute is mandatory. + */ private static void copyStringAttribute( - AnnotationDescriptor annotation, Element element, String attributeName, boolean mandatory - ) { + final AnnotationDescriptor annotation, final Element element, + final String attributeName, final boolean mandatory) { + copyStringAttribute( + annotation, + element, + getJavaAttributeNameFromXMLOne( attributeName ), + attributeName, + mandatory + ); + } + + /** + * Copy a string attribute from an XML element to an annotation descriptor. The name of the annotation attribute is + * explicitely given. + * + * @param annotation annotation where to copy to the attribute. + * @param element XML element from where to copy the attribute. + * @param annotationAttributeName name of the annotation attribute where to copy. + * @param attributeName name of the XML attribute to copy. + * @param mandatory whether the attribute is mandatory. + */ + private static void copyStringAttribute( + final AnnotationDescriptor annotation, final Element element, + final String annotationAttributeName, final String attributeName, boolean mandatory) { String attribute = element.attributeValue( attributeName ); if ( attribute != null ) { - String annotationAttributeName = getJavaAttributeNameFromXMLOne( attributeName ); annotation.setValue( annotationAttributeName, attribute ); } else { diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/entityGraph/OrmXmlParseTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/entityGraph/OrmXmlParseTest.java index eb1f980375..5fe5d02de3 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/entityGraph/OrmXmlParseTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/entityGraph/OrmXmlParseTest.java @@ -26,7 +26,9 @@ package org.hibernate.test.annotations.entityGraph; import org.hibernate.cfg.Configuration; import org.hibernate.internal.util.ConfigHelper; + import org.hibernate.testing.TestForIssue; + import org.junit.Test; @@ -36,7 +38,7 @@ import org.junit.Test; public class OrmXmlParseTest { @Test - @TestForIssue( jiraKey = "HHH-9247" ) + @TestForIssue(jiraKey = "HHH-9247") public void parseNamedAttributeNode() { final Configuration cfg = new Configuration(); cfg.addURL( ConfigHelper.findAsResource( "org/hibernate/test/annotations/entityGraph/orm.xml" ) );