解决方法:
这个问题是由WEB.XML中的一个配置引起的:
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
1.重新写一个类,把spring的org.springframework.orm.hibernate3.support.OpenSessionInViewFilter类内容copy过来~然后自己设置下flushMode=FlushMode.AUTO,再写重写一下
protected void closeSession(SessionFactory sessionFactory,Session session){
session.flush();
super.closeSession(sessionFactory,session);
}
2.配置文件:
<bean id="txProxyTemplate" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"/>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED </prop>
<prop key="remove*">PROPAGATION_REQUIRED </prop>
<prop key="update*">PROPAGATION_REQUIRED </prop>
<prop key="insert*">PROPAGATION_REQUIRED </prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly </prop>
</props>
</property>
</bean>
</beans>
3.检查spring配置文件中的service层配置或在service层加上注解: @Transactional(propagation = Propagation.REQUIRED)