sarunw
sarunw

Reputation: 8176

How to implement change log with JPA?

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 ?

Upvotes: 5

Views: 6435

Answers (2)

James
James

Reputation: 18379

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.

Upvotes: 2

Ralph
Ralph

Reputation: 120791

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.

Upvotes: 4

Related Questions