您的位置:首页 > 大数据 > 人工智能

Could not obtain transaction-synchronized Session for current thread

2017-11-02 20:48 1796 查看
spring4. 3 +  hibernate4.3 执行sessionFactory.getCurrentSession() 抛 Could not obtain transaction-synchronized Session for current thread  异常。

解决方法:添加

<filter>
<filter-name>openSessionInView</filter-name>
<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

OpenSessionInViewFilter的主要功能是用来把一个Hibernate Session和一次完整的请求过程对应的线程相绑定。Open Session In View在request把session绑定到当前thread期间一直保持hibernate session在open状态,使session在request的整个期间都可以使用。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐