-->
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: session closes with commit() - is it a configurable ?
PostPosted: Fri Jun 26, 2009 3:57 am 
Newbie

Joined: Tue Jun 09, 2009 4:49 am
Posts: 5
Hi all !
I'm using Hibernate to update a Database schema and invoke some Stored Procedures.
I can see that when I issue commit(), then the Session is closed, as a matter of fact If I issue
session.close() afterwards, I'll get an error "Session is closed!".
Is it configurable to close() the session with/without commit() ?

Here's an example:

Code:
      Session session = SessionFactoryUtil.getSessionFactory().getCurrentSession();
      String toReturn = null;
      CallableStatement cs = null;
      try {
         session.beginTransaction();
         cs = session.connection().prepareCall("{call prc_insert_voip(?)}");
         cs.setLong(1, idSubnetting);

         cs.execute();

         session.getTransaction().commit();
      }
      catch (Exception exc) {
         exc.printStackTrace();
      }
      finally {
         try {
                                                   cs.close();
            // THIS ISSUES AN ERROR "Session is closed"
                                                   session.close();
            
         } catch (SQLException e) {
            e.printStackTrace();
         }

         session.close();
      }

Thanks a lot
John


Top
 Profile  
 
 Post subject: Re: session closes with commit() - is it a configurable ?
PostPosted: Fri Jun 26, 2009 5:53 am 
Newbie

Joined: Tue Jun 23, 2009 3:31 am
Posts: 10
The code does not have any problem except that finally block trying to close session twice. Are u sure that u r getting error in the first session.close()?

Commit is applicable for a transaction and u can create as many transactions as you want & commit it. This should not close the session.


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.