Hi all,
I've got a Session.load(..) issue I'd like some pointers with...
I'm using hibernate Sessions across web-requests, as described in the refrence docs section 14.3.1: "Long session with automatic versioning"
I am purposely holding references to some objects that I load, and dropping references to others... (depending on whether I need to cache them or not etc.)
Because of the structure of the various code components that a single request thread goes through, it is sometimes possible for a load() to be called for a given entity Id more than once for the session. This results in the following type of exception:
Code:
net.sf.hibernate.HibernateException: The object with that id was already loaded by the Session: [com.foo.Foo#297e80a3f8eb5933dd33f333433ffdcd3]
My questions are:
1- Why can't Hibernate just go ahead an return the instance that it did before?
2- If the Hibernate Session has a handle to the instance it previously load()'ed, is there a way I can get a hold of it from Hibernate since #1 doesn't happen? -- I notice there are contains() and evict() methods on the session, but not any accessor that I can find.
3- Any suggested work-arounds? (For various reasons, I can't hold onto the previously loaded object and pass it around between components - for instance because component A that does the first load has no idea that component B will be doing a second load of the same object)
Also (An unrelated question): if I use update() on a object (that contains Lists etc.) to 'reconnecti' it to a new session, and the object has a "version" property for optimistic locking, does the update short circuit as soon as it detects the version # is the same?
thanks,
james