首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

hibernate+spring事务,该怎么解决

2012-01-22 
hibernate+spring事务1.使用spring管理事务,dao层使用springgetHibernateTemplate操作数据库2.web.xml里有

hibernate+spring事务
1.使用spring管理事务,dao层使用spring getHibernateTemplate操作数据库
2.web.xml里有这样的配置

XML code
<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>


事务配置
XML code
<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 进行更新操作时不刷新缓存就修改数据库数据。

[解决办法]
你这个hibernate是不是配置了二级缓存?
如果是这样的话应该涉及到二级缓存访问数据库策略的问题了,baidu一下应该可以查到
------解决方案--------------------


学习了。

热点排行