Have you experienced this incredibly odd error using ColdFusion ORM:

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

This is really cryptic and most likely you have a parent to child relationship and you are most likely wiping or wanting to wipe all the references of the child.  We usually can do this via:

// wipe out the children

parent.setChildren( [] )

We then proceed to maybe put more children into the collection:

parent.addChild( objX );

parent.addChild( objY );

// Now save

transaction{

entitySave( parent );

}

This is where you get that magical Hibernate error. The issue is that the existing collection is now de-referenced, you completely wiped it so Hibernate has no clue what to do with it. So to resolve this, just clear the collection instead and voila!

// use java

parent.getChildren().clear();

// or use CF

arrayClear( parent.getChildren() );

That's it, this tells Hibernate that the collection is removed first and then you added some more children.