Hibernate version:
2.1
Hi all,
Short version:
If an object exists in two sessions, and is updated in one, is there any way to propagate that change to the other session?
Longer version:
My application uses Hibernate in a service layer that's invoked from .NET clients via SOAP requests. I am using Castor to marshal/unmarshal objects on the server side, with a custom serializer that ignores uninitialized collections.
I am using one long Hibernate session per client (calling reconnect and disconnect for each transaction) in order to track the state of these lazy collections as objects go back and forth over the wire. This works great with single users, but for multiple users, long sessions are now causing some concurrency issues with stale data.
Here's a use case that demonstrates the issue, using a User entity as an example:
*Client 1 opens a new session, loads the User, disconnects the session
*Client 2 opens a new session, loads the User, disconnects the session
*Client 1 changes a property on User, reconnects the session, updates the object and disconnects
*Client 2 reconnects the session, loads the same User again, disconnects the session - the changes made by client 1 are NOT present, its a stale object from the cache, no query is run against the DB.
I realize that long sessions are problematic, but given the issues with SOAP and lazy loading collections, I don't think I can do this another way.
|