Could not obtain transaction-synchronized Session for current thread

来源:互联网 发布:高晓松酒驾 知乎 编辑:程序博客网 时间:2024/05/17 04:42

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的整个期间都可以使用。

阅读全文
0 0