我的事务是通过<tx:annotation-driven的注解方式去标注的。@Transactional未添加就默认为readonly状态。
之前一直运行的好好的,但是,最近在新的工程里面加这个功能,servcie里面的方法只要没加上@Transactional,就会报错:
No Hibernate Session bound to thread, and configuration does not allow creation。
这是告诉我没有设置事务。只有加上@Transactional才会正常。
查了半天才发现,之前@Transactional未添加就默认为readonly状态,是在web.xml里面设置了:
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
我给加上就行了,不过这种情况对于单元测试可能就有问题了