-->
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.  [ 5 posts ] 
Author Message
 Post subject: URGENT,Concurrency issue,loads the session attached to proxy
PostPosted: Tue Nov 25, 2008 5:21 pm 
Newbie

Joined: Tue Nov 25, 2008 5:10 pm
Posts: 4
When we have multiple threads concurrently running, we have an issue with proxy objects. Meaning when a thread a trying to access a domain object, it is loading the proxy object that is attached to a different session. I do not see any reason why it loads the other session instead of loading the object into the same session. So I am not sure how i could eliminate this issue. Though I am creating a new session per thread, I do not see any issue when one thread is getting executed. This is a race condition and happens only when i have multiple requests simultaneously running.

Any hibernate gurus? Help is greatly appreciated. Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2008 5:51 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I think the proxy is tied to the session that first created the proxy object, and since a session is not thread-safe it will of course be problematic to use the proxy in a way that causes it to be initialized from another thread. Simplest way to ensure that an object is tied to the correct session is to use Session.get(). Eg. something like:

Code:
// obj is the entity that is a proxy
if (!Hibernate.isInitialized(obj))
{
   obj = session.get(obj.getClass(), obj.getId());
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2008 6:00 pm 
Newbie

Joined: Tue Nov 25, 2008 5:10 pm
Posts: 4
see for below reply.


Last edited by seema1 on Tue Nov 25, 2008 6:04 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2008 6:02 pm 
Newbie

Joined: Tue Nov 25, 2008 5:10 pm
Posts: 4
Hi nordborg,

Thanks a bunch for your reply.

Yes, we are using session.get only. Also, we will only an id available initially and so we will load an obj by id. So I can not have an if condition check here.

If the sessions are not thread-safe, then how I could i resolve the issue? And also we have a proxy object containing a list of many-to-one proxy children too.

Help is really appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2008 6:27 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
Also, we will only an id available initially and so we will load an obj by id. So I can not have an if condition check here.


What do you do with the object once you have loaded it with Session.get()? Are you passing it on to another thread? When does the race condition happen? Can you post some code examples to clarify?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.