在Hibernate中强制更新 [英] Force update in Hibernate

查看:119
本文介绍了在Hibernate中强制更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何强制Hibernate更新实体实例,即使实体不是脏?我使用Hibernate 3.3.2 GA,Hibernate Annotations和Hibernate EntityManager。我真的希望Hibernate能够执行通用的UPDATE语句,即使没有实体的属性发生变化。

我需要这个,因为需要调用一些事件侦听器来做一些额外的当应用程序第一次运行时工作。



谢谢! 好的 - 自己找到了。这样做的好处在于:

  Session session =(Session)entityManager.getDelegate(); 
session.evict(entity);
session.update(entity);


How can I force Hibernate to update an entity instance even if the entity is not dirty? I'm using Hibernate 3.3.2 GA, Hibernate Annotations and Hibernate EntityManager btw. I really want Hibernate to execute the generic UPDATE statement even if no property on the entity has changed.

I need this because some event listeners need to get invoked to do some additional work when the application runs for the first time.

Thanks!

解决方案

ok - found it myself. This does the trick:

Session session = (Session)entityManager.getDelegate();  
session.evict(entity);  
session.update(entity);

这篇关于在Hibernate中强制更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆