Author: epbernard
Date: 2010-02-08 08:22:43 -0500 (Mon, 08 Feb 2010)
New Revision: 18730
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
Log:
HHH-4887 force PERSIST cascading when @XToOne is used in a @IdClass case.
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
---
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-02-08
11:07:39 UTC (rev 18729)
+++
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-02-08
13:22:43 UTC (rev 18730)
@@ -1431,7 +1431,8 @@
);
}
else {
- final boolean isMapsId = property.isAnnotationPresent( MapsId.class );
+ final boolean forcePersist = property.isAnnotationPresent( MapsId.class )
+ || property.isAnnotationPresent( Id.class );
if ( property.isAnnotationPresent( ManyToOne.class ) ) {
ManyToOne ann = property.getAnnotation( ManyToOne.class );
@@ -1454,9 +1455,9 @@
joinColumn.setSecondaryTableName( join.getTable().getName() );
}
}
- final boolean mandatory = !ann.optional() || isMapsId;
+ final boolean mandatory = !ann.optional() || forcePersist;
bindManyToOne(
- getCascadeStrategy( ann.cascade(), hibernateCascade, false, isMapsId),
+ getCascadeStrategy( ann.cascade(), hibernateCascade, false, forcePersist),
joinColumns,
!mandatory,
ignoreNotFound, onDeleteCascade,
@@ -1492,9 +1493,9 @@
}
}
//MapsId means the columns belong to the pk => not null
- final boolean mandatory = !ann.optional() || isMapsId;
+ final boolean mandatory = !ann.optional() || forcePersist;
bindOneToOne(
- getCascadeStrategy( ann.cascade(), hibernateCascade, ann.orphanRemoval(),
isMapsId),
+ getCascadeStrategy( ann.cascade(), hibernateCascade, ann.orphanRemoval(),
forcePersist),
joinColumns,
!mandatory,
getFetchMode( ann.fetch() ),
@@ -1529,7 +1530,7 @@
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,
propertyHolder, inferredData, entityBinder,
isIdentifierMapper, mappings );
@@ -2661,7 +2662,7 @@
private static String getCascadeStrategy(
javax.persistence.CascadeType[] ejbCascades, Cascade hibernateCascadeAnnotation,
- boolean orphanRemoval, boolean mapsId) {
+ boolean orphanRemoval, boolean forcePersist) {
EnumSet<CascadeType> hibernateCascadeSet = convertToHibernateCascadeType(
ejbCascades );
CascadeType[] hibernateCascades = hibernateCascadeAnnotation == null ?
null :
@@ -2675,7 +2676,7 @@
hibernateCascadeSet.add(CascadeType.DELETE_ORPHAN);
hibernateCascadeSet.add(CascadeType.REMOVE);
}
- if (mapsId) {
+ if (forcePersist) {
hibernateCascadeSet.add(CascadeType.PERSIST);
}