1.使用spring管理事务,dao层使用spring getHibernateTemplate操作数据库
2.web.xml里有这样的配置<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>flushMode</param-name>
<param-value>AUTO</param-value>
</init-param>
</filter>
事务配置<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
<prop key="create*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="reco*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="edit*">PROPAGATION_REQUIRED</prop>
<prop key="del*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
<prop key="set*">PROPAGATION_REQUIRED</prop>
<prop key="deploy*">PROPAGATION_REQUIRED</prop>
<prop key="submit*">PROPAGATION_REQUIRED</prop>
<prop key="merge*">PROPAGATION_REQUIRED</prop>
<prop key="bulk*">PROPAGATION_REQUIRED</prop>
<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="is*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="have*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="search*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="query*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="select*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="show*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
3.在service层调用dao层save*方法时,除非在getHibernateTemplate().save(entity)后进行getSession().flush()操作,才能保存数据到数据库,否则不插入,使用hibernate session直接save可以问题:如何配置让spring getHibernateTemplate 进行更新操作时不刷新缓存就修改数据库数据。
2.web.xml里有这样的配置<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>flushMode</param-name>
<param-value>AUTO</param-value>
</init-param>
</filter>
事务配置<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
<prop key="create*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="reco*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="edit*">PROPAGATION_REQUIRED</prop>
<prop key="del*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
<prop key="set*">PROPAGATION_REQUIRED</prop>
<prop key="deploy*">PROPAGATION_REQUIRED</prop>
<prop key="submit*">PROPAGATION_REQUIRED</prop>
<prop key="merge*">PROPAGATION_REQUIRED</prop>
<prop key="bulk*">PROPAGATION_REQUIRED</prop>
<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="is*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="have*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="search*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="query*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="select*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="show*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
3.在service层调用dao层save*方法时,除非在getHibernateTemplate().save(entity)后进行getSession().flush()操作,才能保存数据到数据库,否则不插入,使用hibernate session直接save可以问题:如何配置让spring getHibernateTemplate 进行更新操作时不刷新缓存就修改数据库数据。
解决方案 »
- eclipse下开发web项目,火狐报错
- eclipse启动tomcat一直报错,调了一天,未果,求大牛解决!!!
- 类似xslt+xml这类方案有哪些?
- axis webservice生成wsdl文件问题
- struts2取值问题
- 一个成就您梦想的机会!!!
- 如何测试程序是否线程安全
- j2sdk1.4.1 +tomcat5.0+eclipse3.0 +tomcatPluginV3(插件)配置web服务器的问题
- jboss的非事务连接和tomcat的数据库连接池比较起来有什么不同??
- 用XSL显示XML的几个疑问,不懂。
- 求个ssi的例子。
- 【江湖求助啊。。。】毕业设计遇到的难点,求高手进来支招。。
如果是这样的话应该涉及到二级缓存访问数据库策略的问题了,baidu一下应该可以查到
所以你要把service bean中配置transactionInterceptor
你尝试一下,我是这么理解的
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>singleSession</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>flushMode</param-name>
<param-value>AUTO</param-value>
</init-param>
</filter>去掉就好了,为什么?延迟加载和这个有联系么……