File tree Expand file tree Collapse file tree 2 files changed +11
-0
lines changed
main/java/org/hibernate/boot/model/internal
test/java/org/hibernate/orm/test/ondeletecascade Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Original file line number Diff line number Diff line change 50
50
import org .hibernate .mapping .Selectable ;
51
51
import org .hibernate .mapping .SimpleValue ;
52
52
import org .hibernate .mapping .Table ;
53
+ import org .hibernate .mapping .ToOne ;
53
54
import org .hibernate .mapping .Value ;
54
55
import org .hibernate .metamodel .CollectionClassification ;
55
56
import org .hibernate .metamodel .UnsupportedMappingException ;
@@ -2747,6 +2748,13 @@ private void bindUnownedManyToManyInverseForeignKey(
2747
2748
manyToOne .setReferencedPropertyName ( referencedPropertyName );
2748
2749
metadataCollector .addUniquePropertyReference ( targetEntity .getEntityName (), referencedPropertyName );
2749
2750
}
2751
+ // Ensure that we copy over the delete action from the owner side before creating the foreign key
2752
+ if ( property .getValue () instanceof Collection collectionValue ) {
2753
+ manyToOne .setOnDeleteAction ( ( (SimpleValue ) collectionValue .getKey () ).getOnDeleteAction () );
2754
+ }
2755
+ else {
2756
+ manyToOne .setOnDeleteAction ( ( (ToOne ) property .getValue () ).getOnDeleteAction () );
2757
+ }
2750
2758
manyToOne .setReferenceToPrimaryKey ( referencedPropertyName == null );
2751
2759
value .createForeignKey ();
2752
2760
}
Original file line number Diff line number Diff line change @@ -88,5 +88,8 @@ static class A {
88
88
static class B {
89
89
@ Id
90
90
long id ;
91
+ @ ManyToMany (mappedBy = "bs" )
92
+ @ OnDelete (action = OnDeleteAction .CASCADE )
93
+ Set <A > as = new HashSet <>();
91
94
}
92
95
}
You can’t perform that action at this time.
0 commit comments