Question subject: Persisting a class into two tables
Posted: Fri Aug 06, 2010 9:40 am
Joined: Thu Aug 05, 2010 12:06 pm Posts: 1 Has thanked: 0 time Have thanks: 0 time
Hi to all,
I hope to be in the right forum/section. If not sorry...
I'm new to JPA and I have the following problem:
I would like to build historization this way:
I have a class Identity and I would like to have two tables associated with it; Identity(ID) and Identity_History(IDHist). In the first I will only have the actual "state" while in the second I will store all the (previous)states. So, for the first table will be inserts and updates and for the second only inserts(for every insert and update in ID).
In ID I only have the attributes, while in IDHist the attributes + the version numbers.
Is this with JPA mapping and annotations possible? I mean to have only a class(Identity) and two associated tables with "distributed" inserts/updates?
For a better understandin (maybe ) see the attachment.
At the moment my classes look like this:
Code:
... @Entity @Table(name="identity") @SecondaryTable(name = "identity_history", pkJoinColumns = @PrimaryKeyJoinColumn(name = "dbId")) @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement public class Identity { // Identity and Version Fields @Id @GeneratedValue @XmlTransient private int dbId; @XmlElement(name = "identity-id") @Transient private String xmlId; @Version @XmlTransient private int version;