根据错误原理解决Hibernate运行出现No CurrentSessionContext configured!错误
来源:互联网 发布:王宏安 软件所 编辑:程序博客网 时间:2024/05/24 06:46
(1)异常信息如下:
严重: 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)启动调试找到问题原因所在:
问题出错的根本是:No CurrentSessionContext configured! (当然下边的错误解释肯定是很多的!)
表示:没有CurrentSession上下文配置! 这就想到了我们在利用CurrentSession的时候,其实就是getCurrentSession的时候没有在hibernate.cfg.xml文件中配置!
(3)解释原理:
1、在 SessionFactory(会话工厂)启动的时候,Hibernate 会根据配置创建相应的 CurrentSessionContext,
在getCurrentSession()被调用的时候,实际被执行的方法是 CurrentSessionContext.currentSession()。
2、这里的“根据配置”就是如下配置:
* 如果使用的是本地事务(jdbc事务 本地事务:数据库只有一个)
<property name="hibernate.current_session_context_class">thread</property>* 如果使用的是全局事务(jta事务 全局事务:数据库有多个)
<property name="hibernate.current_session_context_class">jta</property>
(4)所以解决问题的办法就是根据需求在hibernate.cfg.xml文件中加上上边的配置即可!
注:转载请注明出处!!
4 0
- 根据错误原理解决Hibernate运行出现No CurrentSessionContext configured!错误
- 解决HIbernate3运行出现No CurrentSessionContext configured!错误
- 解决HIbernate3运行出现No CurrentSessionContext configured!错误
- 解决HIbernate3运行出现No CurrentSessionContext configured!错误
- "No CurrentSessionContext configured"错误(hibernate)
- 解决"No CurrentSessionContext configured"错误
- "No CurrentSessionContext configured"错误
- No CurrentSessionContext configured 错误
- "No CurrentSessionContext configured"错误
- No CurrentSessionContext configured错误
- 错误:org.hibernate.HibernateException:No CurrentSessionContext configured!
- 错误:org.hibernate.HibernateException: No CurrentSessionContext configured!
- 错误:org.hibernate.HibernateException: No CurrentSessionContext configured!
- 错误:org.hibernate.HibernateException: No CurrentSessionContext configured!
- 用Hibernate开发遇到"No CurrentSessionContext configured"错误
- 用Hibernate开发遇到"No CurrentSessionContext configured"错误
- 用Hibernate开发遇到"No CurrentSessionContext configured"错误
- 用Hibernate开发遇到"No CurrentSessionContext configured"错误
- java学习二十四 java循环语句do while
- 《Java 解惑》 第二章 表达式之谜
- Android应用---小火箭Rocket
- RED5 Plugin 及 RED5 Application在Eclipse中的调试
- C++ Primer 第五版 中文版 练习 13.14&13.15&14.16&14.17 个人code
- 根据错误原理解决Hibernate运行出现No CurrentSessionContext configured!错误
- 数字电路设计之有符号乘法的两种实现
- Eclipse的彩色世界-文本语法高亮
- memcpy,strcpy,strncpy
- DLL中导出函数的两种方式
- 如何使用SQLite数据库(翻译的不好,见谅)
- jQuery选择器中last-of-type和first-of-type效果案例
- java中的HashTable,HashMap和HashSet
- Eclipse LogCat 消息清除太快,自动消失的解决方法