-->
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: session was already closed
PostPosted: Wed Jan 24, 2007 3:02 pm 
Newbie

Joined: Wed Jan 24, 2007 2:54 pm
Posts: 6
I use
Hibernate 3.2.1 ga,
c3p0-0.9.0.jar (which is distributed along with hibernate),
jdk 1.4.2,
Oracle 10g XE database.


using the following code

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

session = sessionFactory.getCurrentSession();

Transaction tx = session.beginTransaction();
:::
:::
:::
:::

tx.commit();
session.flush();
session.close();

Exception in thread "main" org.hibernate.SessionException: Session was already closed at session.flush() line


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 6:45 pm 
Regular
Regular

Joined: Sun Sep 17, 2006 2:48 am
Posts: 81
Location: California
When we comit a transaction hibernate by default flushes the session implicitly. So there is no need to explicitly call it. Hope that helps.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 7:03 pm 
Newbie

Joined: Wed Jan 24, 2007 2:54 pm
Posts: 6
I commented out the session.flush() and then tried it again.

Again the same error at session.close() line.

So if we commit the transaction, will session.flush() & session.close() happen automatically?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 7:27 pm 
Regular
Regular

Joined: Sun Sep 17, 2006 2:48 am
Posts: 81
Location: California
Sorry for not being explicit.

Yes, you really dont need both flush and close.
Commit or rollback does those two operations implicitly.

So if after commit/rollback if you need to open a new transaction then you need to create (or get) a new session from the sessionfactory.

Hope that helps.


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.