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.
views:
43answers:
2One 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.
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.