-->
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.  [ 6 posts ] 
Author Message
 Post subject: Are Hibernate Objs thread safe using ThreadLocal pattern ?
PostPosted: Tue Aug 24, 2004 2:18 am 
Newbie

Joined: Wed Jul 21, 2004 9:41 pm
Posts: 11
Hi,
As a newbie, I want to ask a yes/no question.
I use ThreadLocal to make the session thread safe, is that means all objects that query by session or find by session are all thread safe ?

Please, my lord.

Hibernate version:
hibernate 2.1.4

Mapping documents:
N/A

Code between sessionFactory.openSession() and session.close():
N/A

Full stack trace of any exception that occurs:
N/A

Name and version of the database you are using:
N/A

Debug level Hibernate log excerpt:
N/A


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 24, 2004 8:09 am 
Newbie

Joined: Tue Aug 17, 2004 7:38 am
Posts: 12
Location: Z
Hi,

As far as every thread obtain a dedicated session using that pattern, and you'll use the same thread for making calls on the session obtained, you have a isolated session from other threads.

Bye,

Roque


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 25, 2004 4:27 am 
Newbie

Joined: Wed Jul 21, 2004 9:41 pm
Posts: 11
Hi rcnavarro,
Glad to get a reply, OK the session is isolated.
What I concern is the objects that query by this isolated session, are they thread safe too?

Let's assume I have a User object mapped with DB user table.
in the user object I make a hashMap as a member variable.

If this user object is thread safe, I don't need to worriy about the synchronized problem.

What say you ? Thank you very much.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 25, 2004 4:55 am 
Newbie

Joined: Tue Aug 17, 2004 7:38 am
Posts: 12
Location: Z
If you have one session object per thread and you execute operations using this thread on the session, for example, you load and User object, modify the HashMap attribute and finally you update it, you don't be worry, with regards to object access synchronization, if another thread is updating the same object. It is due to every session has independent copies of the data.
Take a look at the points 10.2 and 10.3 of the Hibernate reference document.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 25, 2004 5:13 am 
Newbie

Joined: Wed Jul 21, 2004 9:41 pm
Posts: 11
Should I show my thanks indeed again?
Thank you very much.
I got the blue sky now.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 25, 2004 5:34 am 
Newbie

Joined: Tue Aug 17, 2004 7:38 am
Posts: 12
Location: Z
Only, try to help to others

Good luck!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.