(1) The exception information is as follows:
Severity: Servlet.service () for Servlet Action threw exceptionjava.lang.RuntimeException: <u>no currentsessioncontext Configured!</u>at Com.lc.utils.HibernateUtil.executeQuery (hibernateutil.java:56) at Com.lc.service.UsersService.checkUser (usersservice.java:22) at Com.lc.struts.action.LoginAction.login ( loginaction.java:38) 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:597) at Org.apache.struts.actions.DispatchAction.dispatchMethod ( dispatchaction.java:269) at Org.apache.struts.actions.DispatchAction.execute (dispatchaction.java:170) at Org.apache.struts.chain.commands.servlet.ExecuteAction.execute (executeaction.java:58) at Org.apache.struts.chain.commands.AbstractExecuteAction.execute (abstractexecuteaction.java:67) at Org.apache.struts.chain.commands.ActionCommanDbase.execute (actioncommandbase.java:51) at Org.apache.commons.chain.impl.ChainBase.execute (chainbase.java:190) At Org.apache.commons.chain.generic.LookupCommand.execute (lookupcommand.java:304) at Org.apache.commons.chain.impl.ChainBase.execute (chainbase.java:190) at Org.apache.struts.chain.ComposableRequestProcessor.process (composablerequestprocessor.java:283) at Org.apache.struts.action.ActionServlet.process (actionservlet.java:1913) at Org.apache.struts.action.ActionServlet.doPost (actionservlet.java:462) at Javax.servlet.http.HttpServlet.service ( httpservlet.java:710) at Javax.servlet.http.HttpServlet.service (httpservlet.java:803) at Org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (applicationfilterchain.java:290) at Org.apache.catalina.core.ApplicationFilterChain.doFilter (applicationfilterchain.java:206) at Org.apache.catalina.core.StandardWrapperValve.invoke (standardwrappervalve.java:230) at Org.apache.catalina.core.StandardContextValve.invoke (standardcontextvalve.java:175) at orG.apache.catalina.core.standardhostvalve.invoke (standardhostvalve.java:128) at Org.apache.catalina.valves.ErrorReportValve.invoke (errorreportvalve.java:104) at Org.apache.catalina.core.StandardEngineValve.invoke (standardenginevalve.java:109) at Org.apache.catalina.connector.CoyoteAdapter.service (coyoteadapter.java:261) at Org.apache.coyote.http11.Http11Processor.process (http11processor.java:844) at Org.apache.coyote.http11.http11protocol$http11connectionhandler.process (http11protocol.java:581) at Org.apache.tomcat.util.net.jioendpoint$worker.run (jioendpoint.java:447) at Java.lang.Thread.run (thread.java:619)
(2) Start debugging to find the cause of the problem:
The root of the problem is:no currentsessioncontext configured! (of course, the following error interpretation is certainly a lot!). )
Indicates: No currentsession context Configuration! This is the thought of our use of currentsession, in fact, is getcurrentsession when not configured in the Hibernate.cfg.xml file!
(3) Explanation principle:
1, when sessionfactory (Session factory) is started, Hibernate will create the corresponding Currentsessioncontext according to the configuration ,
When Getcurrentsession () is called, the actual method to be executed is currentsessioncontext.currentsession ().
2, "according to the configuration" here is The following configuration:
* If you are using a local transaction (JDBC Transaction local transaction: only one database)
<property name= "Hibernate.current_session_context_class" >thread</property>
* If you are using a global transaction (JTA Transaction Global transaction: There are multiple databases)
(4) So the solution is to solve the problem is based on the requirements in the Hibernate.cfg.xml file to add the top of the configuration can!
NOTE: Reprint please indicate the source!!
No Currentsessioncontext configured! error in hibernate run based on Error principle