javahibernatehibernate-mapping

Hibernate - A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance


I'm having the following issue when trying to update my entity:

"A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance".

I have a parent entity and it has a Set<...> of some children entities. When I try to update it, I get all the references to be set to this collections and set it.

The following code represents my mapping:

@OneToMany(mappedBy = "parentEntity", fetch = FetchType.EAGER)
@Cascade({ CascadeType.ALL, CascadeType.DELETE_ORPHAN })
public Set<ChildEntity> getChildren() {
    return this.children;
}

I've tried to clean the Set<..> only, according to this: How to "possible" solve the problem but it didn't work.

If you have any ideas, please let me know.

Thanks!


Solution

  • Actually, my problem was about equals and hashcode of my entities. A legacy code can bring a lot of problems, never forget to check it out. All I've done was just keep delete-orphan strategy and correct equals and hashcode.