Hibernate version: 3
We use <many-to-any> for collections of interfaces.
Before adding en entry to a <many-to-any> collection, all entries in the collection must be loaded/materialised first, else
at the post-flush stage, en exception throws:
ERROR AssertionFailure:22 - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: collection was not processed by flush()
at org.hibernate.engine.CollectionEntry.postFlush(CollectionEntry.java:144)
My explanantion to this:
In the event of a add to a many-to-many relation, Hibernate delete all entries in the phsyical table implementation,
then insert the entire new collection.
This is all well in a normal many-to-many bag, but when it comes to the many-to-any bag: while adding the entries
for the entire collection, Hibernate loads/materialises each and every object. Probably because on the any-end, the
class and key are specified, at the same time, "session" ,perhaps, is not
aware of all the entries in the collection. Then an exception at postflush stage: collection not processed.
My solution is simply to load/materialise each and every entry in the collection using session.get(), before an add.
Any comments anyone?
/Kwan
ps, cascade parameter and Hibernate.initialize() only initialize the proxies, so I use session.get() to get loading/materialization. Any shortcut here ?
|