Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.hibernate.mapping.Selectable;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Table;
import org.hibernate.mapping.ToOne;
import org.hibernate.mapping.Value;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.metamodel.UnsupportedMappingException;
Expand Down Expand Up @@ -2702,6 +2703,13 @@ private void bindUnownedManyToManyInverseForeignKey(
manyToOne.setReferencedPropertyName( referencedPropertyName );
metadataCollector.addUniquePropertyReference( targetEntity.getEntityName(), referencedPropertyName );
}
// Ensure that we copy over the delete action from the owner side before creating the foreign key
if ( property.getValue() instanceof Collection collectionValue ) {
manyToOne.setOnDeleteAction( ( (SimpleValue) collectionValue.getKey() ).getOnDeleteAction() );
}
else if ( property.getValue() instanceof ToOne toOne ) {
manyToOne.setOnDeleteAction( toOne.getOnDeleteAction() );
}
manyToOne.setReferenceToPrimaryKey( referencedPropertyName == null );
value.createForeignKey();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,8 @@ static class A {
static class B {
@Id
long id;
@ManyToMany(mappedBy = "bs")
@OnDelete(action = OnDeleteAction.CASCADE)
Set<A> as = new HashSet<>();
}
}