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 4444import org .hibernate .mapping .Selectable ;
4545import org .hibernate .mapping .SimpleValue ;
4646import org .hibernate .mapping .Table ;
47+ import org .hibernate .mapping .ToOne ;
4748import org .hibernate .mapping .Value ;
4849import org .hibernate .metamodel .CollectionClassification ;
4950import org .hibernate .metamodel .UnsupportedMappingException ;
@@ -2702,6 +2703,13 @@ private void bindUnownedManyToManyInverseForeignKey(
27022703 manyToOne .setReferencedPropertyName ( referencedPropertyName );
27032704 metadataCollector .addUniquePropertyReference ( targetEntity .getEntityName (), referencedPropertyName );
27042705 }
2706+ // Ensure that we copy over the delete action from the owner side before creating the foreign key
2707+ if ( property .getValue () instanceof Collection collectionValue ) {
2708+ manyToOne .setOnDeleteAction ( ( (SimpleValue ) collectionValue .getKey () ).getOnDeleteAction () );
2709+ }
2710+ else if ( property .getValue () instanceof ToOne toOne ) {
2711+ manyToOne .setOnDeleteAction ( toOne .getOnDeleteAction () );
2712+ }
27052713 manyToOne .setReferenceToPrimaryKey ( referencedPropertyName == null );
27062714 value .createForeignKey ();
27072715 }
Original file line number Diff line number Diff line change @@ -88,5 +88,8 @@ static class A {
8888 static class B {
8989 @ Id
9090 long id ;
91+ @ ManyToMany (mappedBy = "bs" )
92+ @ OnDelete (action = OnDeleteAction .CASCADE )
93+ Set <A > as = new HashSet <>();
9194 }
9295}
You can’t perform that action at this time.
0 commit comments