开发者

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

开发者 https://www.devze.com 2022-12-25 04:20 出处:网络
In a persistent object, If i change only one field, Is it possible to find out the changed field only through 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

精彩评论

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