码迷,mamicode.com
首页 > 数据库 > 详细

hibernate saveOrUpdate()方法执行数据库操作不成功

时间:2018-11-10 22:45:42      阅读:298      评论:0      收藏:0      [点我收藏+]

标签:xml文件   org   pre   cut   glob   require   指定   xxx   oba   

saveOrUpdate()方法执行数据库操作不成功:这个问题是你的hibernate.xml文件中的事物配置不正确。导致更新的数据是瞬时状态,没有与Session关联。

具体的配置如下:

  

<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
<property name="globalRollbackOnParticipationFailure" value="false" />
</bean>
<!-- 配置事务增强处理Bean,指定事务管理器 -->
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<!-- 配置详细事务处理语义 -->
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />

<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
<tx:method name="find*" propagation="SUPPORTS" read-only="true" />
<tx:method name="select*" propagation="SUPPORTS" read-only="true" />
<tx:method name="load*" propagation="SUPPORTS" read-only="true" />
<!-- 其他采用默认事务方式 -->
<tx:method name="*"/>
</tx:attributes>
</tx:advice>

<!-- Spring aop事务管理 -->
<aop:config>
<!-- 配置切入点 -->
<aop:pointcut id="transactionPointcut"
expression="execution(* com.xxx.service..*Impl.*(..))" />
<!-- 指定在txAdvice切入点应用txAdvice事务增强处理 -->
<aop:advisor pointcut-ref="transactionPointcut"
advice-ref="transactionAdvice" />
</aop:config>

hibernate saveOrUpdate()方法执行数据库操作不成功

标签:xml文件   org   pre   cut   glob   require   指定   xxx   oba   

原文地址:https://www.cnblogs.com/doudou-123/p/9940761.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!