-->
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.  [ 4 posts ] 
Author Message
 Post subject: concurrent transactions
PostPosted: Sun Feb 29, 2004 2:03 pm 
Beginner
Beginner

Joined: Wed Feb 04, 2004 5:21 pm
Posts: 37
I am in the process of implementing a number of worker threads. My simple concern is how many sessions I should use.

Should I use a session per worker thread or can I use a common session. Using a common session, multiple transactions would be created concurrently within the same session.

Is that supported/advisable ?

Henrik


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 29, 2004 2:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
The session is not thread safe, it is not intendet to use it with multiple threads at the same time. Either syncronize the access to the session or use one session per thread.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 29, 2004 3:16 pm 
Beginner
Beginner

Joined: Wed Feb 04, 2004 5:21 pm
Posts: 37
Understood, but if it is synchronised, how will the following behave :

Code:
Transaction tx1 = session.beginTransaction()
session.save(object1)
..

Transaction tx2 = session.beginTransaction()
session.save(object2)
..
tx2.commit()
tx1.commit()



Will tx2.commit() commit both objects

To me it seems that Transmissions are intended to be used sequentially with the previous transaction committed before a new one is begun.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 29, 2004 5:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Please take a look at http://www.hibernate.org/hib_docs/reference/html/transactions.html#transactions-s2 - You should not create multiple transactions for one database connection (a session is usually associated with one database connection unless you use disconnect/reconnect). Just use one session per thread, unless you really know what you are doing.


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