Potential Issue with orphanRemoval = true and FetchType.LAZY in Hibernate 6.6.9.Final

Hello everyone,

I’ve encountered an issue after upgrading to Hibernate 6.6.9.Final from 6.4.10.Final related to the behavior of orphanRemoval = true when combined with FetchType.LAZY.

Issue Description

In previous Hibernate versions, if I had a lazily-loaded collection with orphanRemoval = true and saved the parent entity without explicitly initializing the collection, Hibernate would not attempt to delete any orphans—unless the collection was explicitly modified.

However, after updating to 6.6.9.Final, it seems that Hibernate attempts to remove orphans, even if the lazy collection was never loaded or accessed. This behavior is unexpected and leads to incorrect deletions.

Questions

  1. Is this a known behavior change in Hibernate 6.6.X.Final?
  2. Is there any official documentation explaining this change?
  3. Are there recommended approaches to handle this situation without explicitly initializing every lazy collection?
  4. Is this expected behavior or is it considered a bug?

This sounds like a bug to me. Please try to create a reproducer with our test case template and if you are able to reproduce the issue, create a bug ticket in our issue tracker and attach that reproducer.

Thanks Christian. I managed to reproduce the issue with test case template and created an issue in the issue tracker: Jira

1 Like