Total members 11889 |It is currently Thu Mar 28, 2024 11:49 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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;

   // Data Fields
   @Embedded
   @AttributeOverrides({
       @AttributeOverride(name="attribute", column=@Column(name="username_attribute")),
       @AttributeOverride(name="versionNumber",column=@Column(name="username_versionNumber"))
   })
   private VersionedAttribute<String> username;
   
   @Embedded
   @AttributeOverrides({
       @AttributeOverride(name="attribute", column=@Column(name="password_attribute")),
       @AttributeOverride(name="versionNumber",column=@Column(name="password_versionNumber"))
   })
   private VersionedAttribute<String> password;
   
   @Embedded
   @AttributeOverrides({
       @AttributeOverride(name="attribute", column=@Column(name="isRevoked_attribute")),
       @AttributeOverride(name="versionNumber",column=@Column(name="isRevoked_versionNumber"))
   })
   private VersionedAttribute<Boolean> isRevoked;
   
   @Embedded
   @AttributeOverrides({
       @AttributeOverride(name="attribute", column=@Column(name="revocationReason_attribute")),
       @AttributeOverride(name="versionNumber",column=@Column(name="revocationReason_versionNumber"))
   })
   private VersionedAttribute<String> revocationReason;
...
}



@Embeddable
public class VersionedAttribute<T>
{
   private String versionNumber;
   private T attribute;
   
   public VersionedAttribute()
   {
      
   }

   public VersionedAttribute(String versionNumber, T attribute)
   {
      super();
      this.versionNumber = versionNumber;
      this.attribute = attribute;
   }
...
}


Thanx in advance for anx help

Francesco




Attachments:
JPA-Mapping.jpg
JPA-Mapping.jpg [ 33.87 KiB | Viewed 4335 times ]
Author:
Newbie
User avatar Posts: 1
Have thanks: 0 time

Hi brother , i think your answer is here :
jpa/one-to-many-relation-jpa-example-t6091.html

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : Persisting a class into two tables
 Cascade.All and persisting related entities directly     -  
 Add two tables     -  
 Generating Tables from XML by php     -  
 Optimize All Tables In A MySQL Database     -  
 Database Cashing tables results model     -  
 Define class helper class to check the method existance     -  
 java abstract class,concrete class and interface     -  
 relationship between the Canvas class and the Graphics class     -  
 inner class that is a member of an outer class?     -  
 Define class inside another class C++     -  



Topic Tags

Java JPA
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com