-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Long sessions and concurrency
PostPosted: Fri Nov 19, 2004 6:28 pm 
Beginner
Beginner

Joined: Tue Aug 26, 2003 4:19 pm
Posts: 42
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.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 20, 2004 7:22 am 
Regular
Regular

Joined: Fri Jul 16, 2004 3:04 pm
Posts: 52
Location: Wiltshire UK
There are perhaps better ways to handle long transactions. You might be better off keeping the User object in the HttpSession & then using session.update(Object o) to reassociate the object with a new Hibernate Session before modifying it. This way the data in your User object should be fresh before you modify it the second time. Have you read Hibernate in Action? It really is worth reading as it explains all of this stuff quite well.

HTH
Paul :-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.