Strategy for history tables

View: New views
2 Messages — Rating Filter:   Alert me  

Strategy for history tables

by JeffTalley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is there a good strategy to deal with history/journal tables with JPA. For example, say I have a table named PERSON that has the fields: ID, VERSION, FIRST_NAME, LAST_NAME with a primary key of ID. Any time that the value of FIRST_NAME or LAST_NAME changes, I would like a new entry to be made in another table named PERSON_HIST that has the exact same columns except that ID and VERSION are a composite primary key (this is quite often done with a DB trigger). There could even be additional columns in the history table to track timestamps or user ID's of who made the change. I would like to have a class named Person that maps to PERSON and a subclass of Person named PersonHistory that maps to PERSON_HIST. If I create this hierarchy and do the mapping, JPA wants to persist the inheritance which is not what I want (I want them to be treated as separate entities). When these tables get to be 15+ columns in size, it is a pain to create two nearly identical classes and try to keep them in sync has development progresses. Any ideas?

Re: Strategy for history tables

by James Sutherland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If you use EclipseLink there is history support as you have described.

You can use a DescriptorCustomizer to enable history on a ClassDescriptor.

See,
http://www.eclipse.org/eclipselink/api/1.1.1/org/eclipse/persistence/history/HistoryPolicy.html


http://wiki.eclipse.org/Configuring_a_Descriptor_(ELUG)#Configuring_a_History_Policy