Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (3.9k points)

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!

1 Answer

0 votes
by (46k points)
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.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Jul 22, 2019 in Java by Anvi (10.2k points)

Browse Categories

...