Skip to content

Commit 62a650b

Browse files
committed
HHH-19732 Fix wrong resetting of owned on-delete action when processing inverse collection
1 parent 42c6185 commit 62a650b

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2747,6 +2747,8 @@ private void bindUnownedManyToManyInverseForeignKey(
27472747
manyToOne.setReferencedPropertyName( referencedPropertyName );
27482748
metadataCollector.addUniquePropertyReference( targetEntity.getEntityName(), referencedPropertyName );
27492749
}
2750+
// Ensure that we copy over the delete action from the owner side before creating the foreign key
2751+
manyToOne.setOnDeleteAction( ( (SimpleValue) ( (Collection) property.getValue() ).getKey() ).getOnDeleteAction() );
27502752
manyToOne.setReferenceToPrimaryKey( referencedPropertyName == null );
27512753
value.createForeignKey();
27522754
}

hibernate-core/src/test/java/org/hibernate/orm/test/ondeletecascade/OnDeleteManyToManyTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)