Org.hibernate.SessionException:Session was already closed
Source: Internet
Author: User
Problems encountered: The following issues occur when you test hibernate to create a table to a database Org.hibernate.SessionException:Session was already closed at Org.hibernate.internal.SessionImpl.close ( sessionimpl.java:344) at Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at Sun.reflect.NativeMethodAccessorImpl.invoke (Unknown Source) at Sun.reflect.DelegatingMethodAccessorImpl.invoke ( Unknown source) at Java.lang.reflect.Method.invoke (Unknown source) at Org.hibernate.context.internal.threadlocalsessioncontext$transactionprotectionwrapper.invoke ( threadlocalsessioncontext.java:352) at Com.sun.proxy. $Proxy 5.close (Unknown Source) at Studentstest.destroy ( STUDENTSTEST.JAVA:40) at Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at Sun.reflect.NativeMethodAccessorImpl.invoke (Unknown Source) at Sun.reflect.DelegatingMethodAccessorImpl.invoke ( Unknown source) at Java.lang.reflect.Method.invoke (Unknown source) at Org.junit.runners.model.frameworkmethod$1. Runreflectivecall (frameworkmethod.java:45) at Org.junit.internal.runners.model.ReflectiveCallable.run ( ReflectivecallABLE.JAVA:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively (frameworkmethod.java:42) at Org.junit.internal.runners.statements.RunAfters.evaluate (runafters.java:36) at Org.junit.runners.ParentRunner.runLeaf (parentrunner.java:263) at Org.junit.runners.BlockJUnit4ClassRunner.runChild (blockjunit4classrunner.java:68) at Org.junit.runners.BlockJUnit4ClassRunner.runChild (blockjunit4classrunner.java:47) at Org.junit.runners.parentrunner$3.run (parentrunner.java:231) at Org.junit.runners.parentrunner$1.schedule ( PARENTRUNNER.JAVA:60) at Org.junit.runners.ParentRunner.runChildren (parentrunner.java:229) at org.junit.runners.parentrunner.access$000 (parentrunner.java:50) at Org.junit.runners.parentrunner$2.evaluate ( parentrunner.java:222) at Org.junit.runners.ParentRunner.run (parentrunner.java:300) at Org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run (junit4testreference.java:86) at Org.eclipse.jdt.internal.junit.runner.TestExecution.run (testexecution.java:38) at Org.eclipse. Jdt.internal.junit.runner.RemoteTestRunner.runTests (remotetestrunner.java:459) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (remotetestrunner.java:675) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (remotetestrunner.java:382) at Org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (remotetestrunner.java:192)
Problem solving: There are two ways of creating a Session object. 1, Session = Sessionfactory.getcurrentsession (); 2, Session = Sessionfactory.opensession (); When using the first method, you need to use Session.close () to close the Session object When you use the second method, you do not need to call the above method because the session object is automatically closed, and if you close the object program using the first method, the above error occurs. If you must manually close, you need to add isopen () to determine.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.