Hibernate version:
2.1.7
Hi!
In our company we use Hibernate2 as a persistency framework for our rich-client application. Hibernate is deployed on the client side and that means that several instances of Hibernate access a database at the same time (so it is not a web application).
We use versioning (optimistic locking) to distinguish, if a row in a database was modified by another instance of Hibernate. Our session is “long”, actually it is very long, because it is opened when the application starts and it is closed when the application closes.
I’m trying to solve a problem, how to reload an object from the database if it was already loaded and modified by another instance of Hibernate (overriding any changes = first wins). My question is:
Is it possible to recover from StaleObjectStateException without closing the session? If yes, what is a common “pattern” how to do it?
I’ve tried to detach (evict(Object)) and reload (load(Object, Serializable)) the modified object, but I’m still getting the StaleObjectStateException during the subsequent flush() calls.
To close and reopen session seems to help, but then I have to deal with many other problems (like LazyInitializationExceptions) – just the application assumes that the objects are always attached.
Any help or idea would be highly appreciated. Thank you.
|