After few hours debugging session with Hibernate we found the problem. We manually (e.g. in java code) alter hibernate configuration by setting some collection mappings to be immutable. Something like that:
Code:
for (Iterator<Collection> iter = configuration.getCollectionMappings(); iter.hasNext();) {
Collection collection = iter.next();
collection.setMutable(false);
}
Unfortunately, some of the collection mappings in xml files were defined with cascade="delete-orphan"
delete-orphan style of cascading doesn't work with immutable collections. Assertion error is thrown whenever session is flushed.
So, if you define collection mappings like that:
mutable="false" cascade="delete-orphan"
you will face assertion error on flush. Perhaps hibernate should fail-fast during configuring SessionFactory? Is it a bug? Throwing nicer exception like "you cannot cascade changes from immutable collection ... " + some info how to fix it would be great :)
We fixed our problem by removing cascade from immutable collections (it's a bit hackey, though):
Code:
collection.setMutable(false);
String propertyName = collection.getNodeName();
collection.getOwner().getProperty(propertyName).setCascade("none");