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!!