有没有办法只使用Hibernate从对象中获取已更改的列? [英] Is there a way to get only the changed columns from an object using Hibernate?

查看:98
本文介绍了有没有办法只使用Hibernate从对象中获取已更改的列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个持久对象中,如果我只更改一个字段,是否有可能只通过Hibernate找出已更改的字段?
我知道我可以得到整个旧行和新行并进行比较。

解决方案

一个选项是钩入Hibernate的事件系统(参见 docs )。例如,如果您注册接收 FlushEntityEvent ,然后通过事件的 getDirtyProperties 方法通知您哪些列正在更改。

In a persistent object, If i change only one field, Is it possible to find out the changed field only through Hibernate? I know I can get the entire old row and new row and compare.

解决方案

One option is to hook into Hibernate's event system (see docs). For example, if you registered to receive FlushEntityEvent, then you'd be informed as to which columns were changing via the getDirtyProperties method of the event.

这篇关于有没有办法只使用Hibernate从对象中获取已更改的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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