hibernate-orm icon indicating copy to clipboard operation
hibernate-orm copied to clipboard

HHH-4301 Allow OnDelete on ElementCollection.

Open ettavolt opened this issue 1 year ago • 5 comments

CollectionBinder#oneToMany is only for association, not for element collection:

  1. #scheduleSecondPass expects MappedBy, which is only available for associations;
  2. #detectMappedByProblem really wants to check association, because only for it JPA requires join table by default;
  3. #noAssociationTable cares about association again, because otherwise element won't be a persistent class;
  4. #bindManyToManySecondPass:
    1. #logManyToManySecondPass uses oneToMany only to differentiate between different collection of entities;
    2. #bindManyToManyInverseForeignKey is run for association only.

https://hibernate.atlassian.net/browse/HHH-4301

ettavolt avatar Aug 26 '23 20:08 ettavolt

I'd appreciate some help understanding why derby and oracle time out, why it doesn't build for s390x (that J9 doesn't know var?), why tidb cannot send emails.

ettavolt avatar Aug 26 '23 23:08 ettavolt

I'd appreciate some help understanding why derby and oracle time out, why it doesn't build for s390x (that J9 doesn't know var?), why tidb cannot send emails.

We've had some problems lately, but those failures aren't related to your work.

gavinking avatar Aug 27 '23 08:08 gavinking

This looks like a reasonable start. And this change should result in correct generation of the on delete cascade constraint.

But I imagine that isn't quite enough. We also need to suppress execution of the SQL delete statement to clean up the element collection when remove()-ing its owning entity. That's going to require slightly more work (though I doubt it's difficult).

gavinking avatar Aug 27 '23 08:08 gavinking

While I agree that this optimization (avoid explicit element collection deletes when FK is cascading) is a useful one, I'd prefer to implement it separately from fixing the bug. If we are to rely on particular DB configuration, we also need to teach Hibernate to verify its presence when jakarta.persistence.schema-generation.database.action is VALIDATE. And at this moment Hibernate doesn't even check if FK is there or not, yet alone its options.

Additionally, the effect this annotation has on 1:n will be different. It's hard to imagine all the corner cases that various inheritance strategies and further associations might produce.

ettavolt avatar Aug 27 '23 15:08 ettavolt

@gavinking, what do you think about discussing and implementing the optimization outside this fix?

ettavolt avatar Sep 02 '23 21:09 ettavolt

Superseded by #8375.

gavinking avatar May 14 '24 10:05 gavinking