-->
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: how to reuse the opened session
PostPosted: Tue Sep 16, 2003 9:50 am 
Newbie

Joined: Tue Sep 16, 2003 9:45 am
Posts: 2
Hi,
Can I use the same opened session for update from 1 table and again for querying from another table.I am doing the following and getting 'Connection is busy with another hstmt'

dbSession = session.beginTransaction();
Cat Pricess = new Cat();
princess.setName("Princess");
princess.setSex('F');
dbSession.save(princess);
dbSession.connection(commit);
dbSession.close();

dbSession = session.beginTransaction();
//Logic for querying from some table
dbSession.close();



Any Help greatly appreciated

Thanks in advance.
Srinivas


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 16, 2003 10:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
If there is an exception thrown or you rollback the transaction the session can NOT be reused. Use a session per-transaction approach will save you from potential grief.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2003 8:49 am 
Beginner
Beginner

Joined: Mon Sep 15, 2003 12:41 pm
Posts: 21
david wrote:
If there is an exception thrown or you rollback the transaction the session can NOT be reused. Use a session per-transaction approach will save you from potential grief.


I need more explanation regarding the following statement:

=================
If the Session throws an exception (including any SQLException), you should immediately rollback the transaction, call Session.close() and discard the Session instance. Certain methods of Session will not leave the session in a consistent state.
=================

What those exceptions are? Absolutely any?


Top
 Profile  
 
 Post subject: One session per transaction
PostPosted: Fri Sep 19, 2003 6:17 am 
Newbie

Joined: Tue Aug 26, 2003 10:17 pm
Posts: 5
Hi,

I guess what that means is within your business logic when some operation on a Hibernate Session fail (ie. throws an exception), you should at least close the session, and if you want to do postmortem operation then open another session within the same transaction, so as to keep with the one session per transaction rule.

Clarence


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.