zwwcn

Just another WordPress.com site

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

The logged exception

org.hibernate.HibernateException – “A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance: com.onkarjoshi.hibernate.test.Person.children”

Your likely problem

Looks like you have a Parent entity and a Child entity. The Parent has a collection of Child entities with cascade=”all-delete-orphan”.

You are setting a new collection via the setter thus leaving the original collection unreferenced by the Parent entity. This doesn’t fly well with Hibernate and leaves it confused about what to do.

parent.setChilden(new HashSet<Child>()); // This won’t work. Could be an ArrayList too.

parent.getChildren().clear(); // There, fixed that!

So generally speaking, just clear out the old collection, rather than dereferencing it and creating a new one.

from:http://www.onkarjoshi.com/blog/188/hibernateexception-a-collection-with-cascade-all-delete-orphan-was-no-longer-referenced-by-the-owning-entity-instance/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: