开发者社区> 问答> 正文

什么情况下 才会引起 hibernate 中的session 找不到了?

严重: Servlet.service() for servlet [springMVC] in context with path [/ecampus] threw exception [Request processing failed; nested exception is org.hibernate.HibernateException: No Session found for current thread] with root cause 
org.hibernate.HibernateException: No Session found for current thread 
    at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)
    at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:941) 
    at com.hdecic.news.dao.implement.NewsDaoImplement.getCurrentSession(NewsDaoImplement.java:31)
    at com.hdecic.news.dao.implement.NewsDaoImplement.find(NewsDaoImplement.java:139) 
    at com.hdecic.news.service.implement.NewsServiceImplement.find(NewsServiceImplement.java:60)
    at com.hdecic.news.controller.NewsController.getNewsList(NewsController.java:66) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606)

spring 部分配置如下:

<!-- 注解方式配置事物 -->
    <tx:annotation-driven transaction-manager="transactionManager" />

    <!-- 拦截器方式配置事物 -->
    <tx:advice id="transactionAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="add*" />
            <tx:method name="save*" />
            <tx:method name="repairNews*" />
            <tx:method name="scheduleGetNews*" />
            <tx:method name="update*" />
            <tx:method name="modify*" />
            <tx:method name="edit*" />
            <tx:method name="delete*" />
            <tx:method name="remove*" />
            <tx:method name="repair" />
            <tx:method name="deleteAndRepair" />
            <tx:method name="find" propagation="SUPPORTS" />
            <tx:method name="getNewsList" propagation="SUPPORTS" />
            <tx:method name="get*" propagation="SUPPORTS" />
            <tx:method name="load*" propagation="SUPPORTS" />
            <tx:method name="search*" propagation="SUPPORTS" />
            <tx:method name="datagrid*" propagation="SUPPORTS" />
            <tx:method name="*" propagation="SUPPORTS" />
        </tx:attributes>
    </tx:advice>
    <aop:config>
        <aop:pointcut id="transactionPointcut"
            expression="execution(* com.hdecic.news.service.implement.*Implement.*(..))" />
        <aop:advisor pointcut-ref="transactionPointcut"
            advice-ref="transactionAdvice" />
    </aop:config>

我配置了事务了,也在web.xml文件中,配置了 open session in view... 怎么还是找不见session啊。。还有哪个需要注意的吗?

展开
收起
爵霸 2016-03-04 14:02:26 2305 0
1 条回答
写回答
取消 提交回答
  • 你是不是扫描controller时候把service也加进去的。这样会造成没有事务的。类似:

    <context:component-scan base-package="com.tdu.core.web.controller,com.tdu.bpm.controller"> 
    <context:include-filter type="annotation" 
    expression="org.springframework.stereotype.Controller" /> 
    </context:component-scan> 
    2019-07-17 18:52:13
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载