From 053b676684b7864e7e79b6c4d89bb63704cbc361 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 5 Sep 2012 12:34:03 -0500 Subject: [PATCH] HHH-7568 - Add JPA1.0 compound key compatability when orm descriptor file used to override annotations. (cherry picked from commit 6a48cccd5d250fb25768fd9c7a28c750f002c6f9) --- .../org/hibernate/cfg/AnnotationBinder.java | 62 +++++++++++-------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java index 153c31affb..4ca458e231 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java @@ -1394,33 +1394,41 @@ private static int addProperty( String columnName = element.getAnnotation( Column.class ).name(); for ( XProperty prop : declaringClass.getDeclaredProperties( AccessType.FIELD.getType() ) ) { if ( !prop.isAnnotationPresent( MapsId.class ) ) { - /** - * The detection of a configured individual JoinColumn differs between Annotation - * and XML configuration processing. - */ - boolean isRequiredAnnotationPresent = false; - JoinColumns groupAnnotation = prop.getAnnotation(JoinColumns.class); - if ( ( prop.isAnnotationPresent( JoinColumn.class ) - && prop.getAnnotation( JoinColumn.class ).name().equals( columnName ) ) ) { - isRequiredAnnotationPresent = true; - } else if ( prop.isAnnotationPresent( JoinColumns.class ) ) { - for ( JoinColumn columnAnnotation : groupAnnotation.value() ) { - if ( columnName.equals(columnAnnotation.name() ) ) { - isRequiredAnnotationPresent = true; - break; - } - } - } - if ( isRequiredAnnotationPresent ) { - //create a PropertyData fpr the specJ property holding the mapping - PropertyData specJPropertyData = new PropertyInferredData( - declaringClass, //same dec - prop, // the actual @XToOne property - propertyAccessor, //TODO we should get the right accessor but the same as id would do - mappings.getReflectionManager() - ); - mappings.addPropertyAnnotatedWithMapsIdSpecj( entity, specJPropertyData, element.toString() ); - } + /** + * The detection of a configured individual JoinColumn differs between Annotation + * and XML configuration processing. + */ + boolean isRequiredAnnotationPresent = false; + JoinColumns groupAnnotation = prop.getAnnotation( JoinColumns.class ); + if ( (prop.isAnnotationPresent( JoinColumn.class ) + && prop.getAnnotation( JoinColumn.class ).name().equals( columnName )) ) { + isRequiredAnnotationPresent = true; + } + else if ( prop.isAnnotationPresent( JoinColumns.class ) ) { + for ( JoinColumn columnAnnotation : groupAnnotation.value() ) { + if ( columnName.equals( columnAnnotation.name() ) ) { + isRequiredAnnotationPresent = true; + break; + } + } + } + if ( isRequiredAnnotationPresent ) { + //create a PropertyData fpr the specJ property holding the mapping + PropertyData specJPropertyData = new PropertyInferredData( + declaringClass, + //same dec + prop, + // the actual @XToOne property + propertyAccessor, + //TODO we should get the right accessor but the same as id would do + mappings.getReflectionManager() + ); + mappings.addPropertyAnnotatedWithMapsIdSpecj( + entity, + specJPropertyData, + element.toString() + ); + } } } }