79595010

Date: 2025-04-27 12:26:18
Score: 1
Natty:
Report link
orphanRemoval = true

and

FetchType.LAZY

in Hibernate 6.6.X:


Title: Issue with

orphanRemoval = true

and

FetchType.LAZY

in Hibernate 6.6.X

Body:

I'm encountering an issue while using Hibernate 6.6.X with

orphanRemoval = true

in combination with

FetchType.LAZY

.

Context:

I have a parent entity that has a one-to-many relationship with child entities. I've configured the relationship as follows:

@Entity
public class Parent {
    @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
    private Set<Child> children = new HashSet<>();
}

Problem:

When I try to remove a child entity from the collection of children in the parent entity, it does not seem to get removed properly if the parent entity is loaded lazily. I suspect that it might be related to the way Hibernate handles the lazy loading of collections in conjunction with orphan removal.

Question:

  1. Has anyone experienced this issue with

    orphanRemoval = true
    

    and

    FetchType.LAZY
    

    in Hibernate 6.6.X?

  2. What would be the best approach to ensure that orphaned entities are removed correctly when using lazy loading?

  3. Is there a known workaround or solution to this problem?

Any insights or suggestions would be greatly appreciated!


Feel free to modify any part of the question to better fit your situation or style!

Reasons:
  • Blacklisted phrase (1): appreciated
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: user30329099