-->
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.  [ 3 posts ] 
Author Message
 Post subject: session closed Exception
PostPosted: Tue Apr 11, 2006 4:50 am 
Newbie

Joined: Tue Apr 11, 2006 3:56 am
Posts: 3
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.12

Mapping documents:

Code between sessionFactory.openSession() and session.close():
this is my code:
-----------------------------------------------------
session = HibernateSessionFactory.getSessionFactory().getCurrentSession();
session.beginTransaction();
Subject subject = new Subject();
subject.setName("内科");
session.save(subject);
session.getTransaction().commit();
session.close();
-------------------------------------------------------
but threw Exception:
org.hibernate.SessionException: Session was already closed
at org.hibernate.impl.SessionImpl.close(SessionImpl.java:274)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy0.close(Unknown Source)
at examples.HibernateTest.testInsert(HibernateTest.java:23)
at examples.HibernateTest.main(HibernateTest.java:60)
Exception in thread "main"

------------------------------

why? session is already closed?when it was closed? thanks!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 11, 2006 6:56 am 
Newbie

Joined: Tue Apr 11, 2006 3:56 am
Posts: 3
please tell me why? thanks!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 11, 2006 7:12 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
If you look API docs for org.hibernate.context.ThreadLocalSessionContext:

Quote:
In the interest of usability, it was decided to have this default impl actually generate a session upon first request and then clean it up after the Transaction associated with that session is committed/rolled-back.


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