-
Nov 8th, 2010, 09:18 AM
#1
History tracking with JPA
Does anyone do full data change tracking (history) with JPA? Is it possible to intercept data updates on JPA level or is it only possible when relating on back ends e.g. Hibernate?
Any stories or hints?
Thank you,
Fireball
-
Nov 8th, 2010, 04:15 PM
#2
-
Nov 8th, 2010, 07:32 PM
#3
If you are using EclipseLink as JPA provider, you can use HistoryPolicy
http://wiki.eclipse.org/Configuring_a_Descriptor_%28ELUG%29#Configuring_a_ History_Policy
Basically you duplicate the database structure (tables) without relations and introduces two columns in each table (ROW_START and ROW_END). ROW_START contains the date in wich you insert a new record, with ROW_END in null. If you modify something, the value of ROW_END contains the date of the modification and another row it's created with the same pattern (the table contains duplicate id's).
This is what you mean with "history"?
-
Nov 10th, 2010, 02:38 AM
#4
Hi,
You have several options to intercept the places where DB actions occure:
1) Use JPA annotated lifecycle methods as described in the previous post.
2) Use Spring AOP aspects on DAO methods.
3) Manually code in the DAO or Service methods.
To actually implement the history data structure you also have several options:
1) Implement your own data structure as a new set of entities which you persist manually.
2) Implement a framework for persisting copies of each updated entity to a corresponding history entity.
3) Use an existing solution such as Hibernate Envers or Hades.
Your selection should be based on your case - Do you have many entities you want to save history for? Do you want to track ALL changes or only specific use cases? Do you need to store actual state or just log?
-
Nov 10th, 2010, 02:59 AM
#5
I want to track all changes. We have a custom persistence framework with a history table tracking old and new value changes for alle database columns. Spring Roo has a version column that has similar functionality I guess.
I don't know what's the best solution regarding JPA and performace. Any suggestions?
Thanks Fireball
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules