Total members 9951 | Gratitudes |It is currently Sat Feb 11, 2012 10:03 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 2 posts ] 
Author Question
 Question subject: Persisting a class into two tables
PostPosted: Fri Aug 06, 2010 9:40 am 
Offline
Newbie
User avatar

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;

   // 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 430 times ]
TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Persisting a class into two tables
PostPosted: Sat Aug 07, 2010 12:33 am 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2103
Location: Earth
Has thanked: 39 time
Have thanks: 56 time
Hi brother , i think your answer is here :
jpa/one-to-many-relation-jpa-example-t6091.html

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 2 posts ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 C C++ program help using class  C-C++  Anonymous  0
 Not to find nativeEncoder class jar  Java  Anonymous  0
 PHP class example  PHP examples  msi_333  0
 concrete class  Java  Anonymous  1
 Having a hard time with this class need help deseperately.  Java  Raven50  1

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: Exabot [Bot], Google Adsense [Bot] and 3 guests



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team