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:


Fatal: 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) 


<property name="hibernate.current_session_context_class">jta</property>


(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.

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.