开发者

Is there a way to get only the changed columns from an object using Hibernate?

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


On the basis of one of your comment, my understanding is that you are looking for an auditing solution so I suggest to check Envers which is exactly about this.

The Envers project aims to enable easy auditing/versioning of persistent classes. All that you have to do is annotate your persistent class or some of its properties, that you want to audit, with @Audited. For each audited entity, a table will be created, which will hold the history of changes made to the entity. You can then retrieve and query historical data without much effort.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜