orwtech@gmail.com wrote:
You may need to look in you database for a FK constraint going from Parent to Child table and disable/remove it leaving only the FK constraint going from Child -> Parent.
I have experienced that when the database is created by hibernate one may experience that two foreign keys are created. One in each direction.
Thanks for the tip orwtech. I had the db already, and I checked that it only has one foreign key.
Now the issue is this:
Code:
@OneToMany(mappedBy = "childId", orphanRemoval=true cascade = { javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.MERGE })
private Set<ChildB> bChildrens;
This makes a delete of a ParentA work, deleting all the orphaned childrens in the process, as expected. The problem now is that making an update to ParentA (not related to its children) triggers this exception now:
Code:
org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: