Skip to content

Commit 94ad371

Browse files
EtienneMiretdreab8
authored andcommitted
HHH-9247 Attribute "name" of named-attribute-node maps to "value" of annotation.
1 parent 58e4c67 commit 94ad371

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

hibernate-core/src/main/java/org/hibernate/cfg/annotations/reflection/JPAOverriddenAnnotationReader.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,7 @@ private static void bindNamedAttributeNodes(Element subElement, AnnotationDescri
19491949
List<NamedAttributeNode> annNamedAttributeNodes = new ArrayList<NamedAttributeNode>( );
19501950
for(Element namedAttributeNode : namedAttributeNodes){
19511951
AnnotationDescriptor annNamedAttributeNode = new AnnotationDescriptor( NamedAttributeNode.class );
1952-
copyStringAttribute( annNamedAttributeNode, namedAttributeNode, "value", true );
1952+
copyStringAttribute( annNamedAttributeNode, namedAttributeNode, "value", "name", true );
19531953
copyStringAttribute( annNamedAttributeNode, namedAttributeNode, "subgraph", false );
19541954
copyStringAttribute( annNamedAttributeNode, namedAttributeNode, "key-subgraph", false );
19551955
annNamedAttributeNodes.add( (NamedAttributeNode) AnnotationFactory.create( annNamedAttributeNode ) );
@@ -2903,12 +2903,42 @@ private PrimaryKeyJoinColumn[] buildPrimaryKeyJoinColumns(Element element) {
29032903
return pkJoinColumns;
29042904
}
29052905

2906+
/**
2907+
* Copy a string attribute from an XML element to an annotation descriptor. The name of the annotation attribute is
2908+
* computed from the name of the XML attribute by {@link #getJavaAttributeNameFromXMLOne(String)}.
2909+
*
2910+
* @param annotation annotation descriptor where to copy to the attribute.
2911+
* @param element XML element from where to copy the attribute.
2912+
* @param attributeName name of the XML attribute to copy.
2913+
* @param mandatory whether the attribute is mandatory.
2914+
*/
29062915
private static void copyStringAttribute(
2907-
AnnotationDescriptor annotation, Element element, String attributeName, boolean mandatory
2908-
) {
2916+
final AnnotationDescriptor annotation, final Element element,
2917+
final String attributeName, final boolean mandatory) {
2918+
copyStringAttribute(
2919+
annotation,
2920+
element,
2921+
getJavaAttributeNameFromXMLOne( attributeName ),
2922+
attributeName,
2923+
mandatory
2924+
);
2925+
}
2926+
2927+
/**
2928+
* Copy a string attribute from an XML element to an annotation descriptor. The name of the annotation attribute is
2929+
* explicitely given.
2930+
*
2931+
* @param annotation annotation where to copy to the attribute.
2932+
* @param element XML element from where to copy the attribute.
2933+
* @param annotationAttributeName name of the annotation attribute where to copy.
2934+
* @param attributeName name of the XML attribute to copy.
2935+
* @param mandatory whether the attribute is mandatory.
2936+
*/
2937+
private static void copyStringAttribute(
2938+
final AnnotationDescriptor annotation, final Element element,
2939+
final String annotationAttributeName, final String attributeName, boolean mandatory) {
29092940
String attribute = element.attributeValue( attributeName );
29102941
if ( attribute != null ) {
2911-
String annotationAttributeName = getJavaAttributeNameFromXMLOne( attributeName );
29122942
annotation.setValue( annotationAttributeName, attribute );
29132943
}
29142944
else {

hibernate-core/src/test/java/org/hibernate/test/annotations/entityGraph/OrmXmlParseTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626

2727
import org.hibernate.cfg.Configuration;
2828
import org.hibernate.internal.util.ConfigHelper;
29+
2930
import org.hibernate.testing.TestForIssue;
31+
3032
import org.junit.Test;
3133

3234

@@ -36,7 +38,7 @@
3638
public class OrmXmlParseTest {
3739

3840
@Test
39-
@TestForIssue( jiraKey = "HHH-9247" )
41+
@TestForIssue(jiraKey = "HHH-9247")
4042
public void parseNamedAttributeNode() {
4143
final Configuration cfg = new Configuration();
4244
cfg.addURL( ConfigHelper.findAsResource( "org/hibernate/test/annotations/entityGraph/orm.xml" ) );

0 commit comments

Comments
 (0)