According to the error principle to solve the hibernate run appears no Currentsessioncontext configured! error

Source: Internet
Author: User


(1) The exception information is as follows:

Serious: Servlet.service () for Servlet action threw exception java.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, there must be a lot of wrong explanations below.) )

Indicates: There is no currentsession context configuration. This is the thought of our use of currentsession when, in fact, is getcurrentsession when not in the Hibernate.cfg.xml file configuration.

(3) Principle of interpretation:

1. When the Sessionfactory (Session factory) is started, Hibernate will create the corresponding Currentsessioncontext according to the configuration.

When Getcurrentsession () is invoked, the method that is actually executed is currentsessioncontext.currentsession ().

2, here "according to the configuration" 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: Database has multiple)

(4) So the solution to the problem is based on the requirements of the Hibernate.cfg.xml file to add the above configuration can be.


NOTE: Reprint please indicate the source.


Related Article

Contact Us

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.

Tags Index: