Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement change log with JPA?

Tags:

jpa

changelog

I have an entity class manged by with JPA, and I have one entity that needs to be loged changes in its property. Does JPA provides any ways to handle this kind of requirement ?

like image 571
sarunw Avatar asked Apr 21 '11 10:04

sarunw


2 Answers

If you use Hibernate as JPA provider then have a look at Hibernate-Envers.

If you use Spring, then have at Hades, or its successor Spring-Data-JPA.

Both (Envers and Hades/Spring-Data-JPA) provide auditing functionality. Hibernate Envers is very powerful and Hades/Spring-Data-JPA is more light (Hades reference, chapter auditing).

If you do not want/can use any of them, then may you have to hook in the entity lifecycle. with @PostUpdate and co.

like image 189
Ralph Avatar answered Oct 05 '22 23:10

Ralph


See,

http://en.wikibooks.org/wiki/Java_Persistence/Advanced_Topics#History

and,

http://en.wikibooks.org/wiki/Java_Persistence/Auditing_and_Security

If you are using EclipseLink it include historical support. You can enable a class to have all of its changes tracked in a separate historical table.

like image 43
James Avatar answered Oct 05 '22 22:10

James