The AssertionFailure that occurs when a user is accessing a child collection in the parent during the load of the parent has been pretty well documented and discussed.
http://www.hibernate.org/Documentation/FAQsFromTheForum#A32
http://forum.hibernate.org/viewtopic.php?t=928523&highlight=isinitialized
We were having the same problem and don't want to introduce a Hibernate-specific check (if (Hibernate.isInitialized(coll)) ...) into our domain model. At the end of the last post above, Gavin stated:
Quote:
If only add() didn't have a return value, I could do it internally
Before reading this post I was wondering why the AssertionFailure is thrown in the first place. If the collection is initializing, simply add the new object to the templist collection until the hibernate collection proxy is initialized. At that time, all of the objects in templist are copied over. I'm probably missing something else here since Gavin's reply about return value on add() doesn't make much sense to me. Wouldn't this approach work? Does it cause other unwanted side-effects?
The primary concern here is that this is the first bit of code we have written that introduces an anti-pattern into our domain model. This is the only case using Hibernate (so far) that we have to do something unexpected (from our domain models perspective) to work nicely with our OR mapping solution.