Hello,
So we've been using Hibernate (version 3.2.3) for our project and we're encountering a pretty annoying (but possibly "normal") issue.
To make it simple, we have many 1--* relationships, like this:
[ Parent ] 1 ---------- * [ Child ]
These relationships are lazy, so that the collection of children associated with a parent is not fetched until one calls parent.getChildren().
Now the issue is, say we have two concurrent threads running, T1 and T2. T1 calls parent.getChildren(), hence Hibernate starts initializing (loading) the collection. In the meantime, T2 calls parent.getChildren(). There, an exception occurs: "Illegal access to loading collection".
Both threads are using the same hibernate session. We use only one session for the whole app because we need a constant 1-1 mapping between our Java object tree and the database rows, and we want to minimize the number of accesses to the database (the actual "persist" action is supposed to be done when the user has finished working on his/her data).
Is there any way to make this work? Or are we not handling this the right way?
Thanks in advance for your help. :)
|