Skip to content

Commit

Permalink
HHH-9247 Attribute "name" of named-attribute-node maps to "value" of …
Browse files Browse the repository at this point in the history
…annotation.
  • Loading branch information
EtienneMiret authored and dreab8 committed Mar 9, 2015
1 parent d791dcb commit 7d6989e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
Expand Up @@ -1949,7 +1949,7 @@ private static void bindNamedAttributeNodes(Element subElement, AnnotationDescri
List<NamedAttributeNode> annNamedAttributeNodes = new ArrayList<NamedAttributeNode>( );
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 ) );
Expand Down Expand Up @@ -2903,12 +2903,42 @@ private PrimaryKeyJoinColumn[] buildPrimaryKeyJoinColumns(Element element) {
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 {
Expand Down
Expand Up @@ -26,7 +26,9 @@

import org.hibernate.cfg.Configuration;
import org.hibernate.internal.util.ConfigHelper;

import org.hibernate.testing.TestForIssue;

import org.junit.Test;


Expand All @@ -36,7 +38,7 @@
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" ) );
Expand Down

0 comments on commit 7d6989e

Please sign in to comment.