免费刷金币,请点击这里
职业课程 > 员工信息系统 4 章、后台拦截器及账号登录、系统模块的设计及实现
客服QQ:1206116161
zhayonng

关于hibernate中的No Hibernate Session bound to thread问题

zhayonng 于 2019-01-05 01:16:59 发起求助
(67)
(3)
举报

测试findAllAccount方法时抛出这个问题,之前好像把impl包中的文件删了


exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause

org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
	org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:64)
	org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:542)
	com.emp.dao.AbstractDao.findSession(AbstractDao.java:14)
	com.emp.dao.AbstractDao.findAll(AbstractDao.java:44)
	com.emp.dao.AbstractDao$FastClassByCGLIB$5e60ba81.invoke(<generated>)
	org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
	org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
	com.emp.intercept.MyMethodIntercept.invoke(MyMethodIntercept.java:14)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
	com.emp.dao.AccountDAO$EnhancerByCGLIB$2b81a124.findAll(<generated>)
	com.emp.service.impl.AccountServiceImpl.findAllAccount(AccountServiceImpl.java:21)
	com.emp.service.impl.AccountServiceImpl$FastClassByCGLIB$5d561d6a.invoke(<generated>)
	org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
	org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
	com.emp.intercept.MyMethodIntercept.invoke(MyMethodIntercept.java:14)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
	com.emp.service.impl.AccountServiceImpl$EnhancerByCGLIB$c6ae943a.findAllAccount(<generated>)
	com.emp.controller.DemoController.findAllAccount(DemoController.java:33)
	com.emp.controller.DemoController$FastClassByCGLIB$e81ee13e.invoke(<generated>)
	org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
	org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
	com.emp.intercept.MyMethodIntercept.invoke(MyMethodIntercept.java:14)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:91)
	org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
	com.emp.controller.DemoController$EnhancerByCGLIB$4b5ad18e.findAllAccount(<generated>)
	sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	java.lang.reflect.Method.invoke(Method.java:497)
	org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
	org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
	org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
	org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
	org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
	org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.13 logs.


  • _Kiro
    _Kiro - 01月05日 (0)

    1. 先看看配置文件中有没有开启事务控制。

    2. 在方法或类上面增加一个事务的注解控制

    _Kiro
    zhayonng - 01月08日 (0) @ _Kiro

    网页出bug了没法提问了,所以只能在这里提问了

    在部门管理模块的数据列表这一节,检验地址http://localhost:8008/myemp/mgr/department/findDepartmentList?search=&page=1

    后台抛出空指针异常


  • zhayonng
    zhayonng - 01月05日 (0)

    问题找到了,主要原因是重新建了一个实现类后少写了一个Transactional注解

扫码关注TE官方微博 扫码关注TE官方微博
回复X
举报X