HHH-4887 force PERSIST cascading when @XToOne is used in a @IdClass case.

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18730 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Emmanuel Bernard 2010-02-08 13:22:43 +00:00
parent 7cb83cac95
commit 3d911bd658
1 changed files with 9 additions and 8 deletions

View File

@ -1431,7 +1431,8 @@ public final class
); );
} }
else { else {
final boolean isMapsId = property.isAnnotationPresent( MapsId.class ); final boolean forcePersist = property.isAnnotationPresent( MapsId.class )
|| property.isAnnotationPresent( Id.class );
if ( property.isAnnotationPresent( ManyToOne.class ) ) { if ( property.isAnnotationPresent( ManyToOne.class ) ) {
ManyToOne ann = property.getAnnotation( ManyToOne.class ); ManyToOne ann = property.getAnnotation( ManyToOne.class );
@ -1454,9 +1455,9 @@ public final class
joinColumn.setSecondaryTableName( join.getTable().getName() ); joinColumn.setSecondaryTableName( join.getTable().getName() );
} }
} }
final boolean mandatory = !ann.optional() || isMapsId; final boolean mandatory = !ann.optional() || forcePersist;
bindManyToOne( bindManyToOne(
getCascadeStrategy( ann.cascade(), hibernateCascade, false, isMapsId), getCascadeStrategy( ann.cascade(), hibernateCascade, false, forcePersist),
joinColumns, joinColumns,
!mandatory, !mandatory,
ignoreNotFound, onDeleteCascade, ignoreNotFound, onDeleteCascade,
@ -1492,9 +1493,9 @@ public final class
} }
} }
//MapsId means the columns belong to the pk => not null //MapsId means the columns belong to the pk => not null
final boolean mandatory = !ann.optional() || isMapsId; final boolean mandatory = !ann.optional() || forcePersist;
bindOneToOne( bindOneToOne(
getCascadeStrategy( ann.cascade(), hibernateCascade, ann.orphanRemoval(), isMapsId), getCascadeStrategy( ann.cascade(), hibernateCascade, ann.orphanRemoval(), forcePersist),
joinColumns, joinColumns,
!mandatory, !mandatory,
getFetchMode( ann.fetch() ), getFetchMode( ann.fetch() ),
@ -1529,7 +1530,7 @@ public final class
joinColumn.setSecondaryTableName( join.getTable().getName() ); joinColumn.setSecondaryTableName( join.getTable().getName() );
} }
} }
bindAny( getCascadeStrategy( null, hibernateCascade, false, isMapsId), //@Any has not cascade attribute bindAny( getCascadeStrategy( null, hibernateCascade, false, forcePersist), //@Any has not cascade attribute
joinColumns, onDeleteCascade, nullability, joinColumns, onDeleteCascade, nullability,
propertyHolder, inferredData, entityBinder, propertyHolder, inferredData, entityBinder,
isIdentifierMapper, mappings ); isIdentifierMapper, mappings );
@ -2661,7 +2662,7 @@ public final class
private static String getCascadeStrategy( private static String getCascadeStrategy(
javax.persistence.CascadeType[] ejbCascades, Cascade hibernateCascadeAnnotation, javax.persistence.CascadeType[] ejbCascades, Cascade hibernateCascadeAnnotation,
boolean orphanRemoval, boolean mapsId) { boolean orphanRemoval, boolean forcePersist) {
EnumSet<CascadeType> hibernateCascadeSet = convertToHibernateCascadeType( ejbCascades ); EnumSet<CascadeType> hibernateCascadeSet = convertToHibernateCascadeType( ejbCascades );
CascadeType[] hibernateCascades = hibernateCascadeAnnotation == null ? CascadeType[] hibernateCascades = hibernateCascadeAnnotation == null ?
null : null :
@ -2675,7 +2676,7 @@ public final class
hibernateCascadeSet.add(CascadeType.DELETE_ORPHAN); hibernateCascadeSet.add(CascadeType.DELETE_ORPHAN);
hibernateCascadeSet.add(CascadeType.REMOVE); hibernateCascadeSet.add(CascadeType.REMOVE);
} }
if (mapsId) { if (forcePersist) {
hibernateCascadeSet.add(CascadeType.PERSIST); hibernateCascadeSet.add(CascadeType.PERSIST);
} }