These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Composite primary and foreign keys
PostPosted: Tue Aug 04, 2009 10:55 am 
Beginner
Beginner

Joined: Fri Nov 11, 2005 4:35 pm
Posts: 23
Hi,

I have two classes and a primaryKey class.
I'm Struggling with my foreign keys.

Code:
@Entity
@Table(name = "company")
public class Company {

   @Id
   private EffectiveDatePrimaryKey primaryKey = new EffectiveDatePrimaryKey();
   
   private String name;
   
   // ---------------------------- GETTERS + SETTERS


Code:
@Embeddable
public class EffectiveDatePrimaryKey implements Serializable{

   private static final long serialVersionUID = 1L;

   private long id;
   
   private Date effectiveDate;


Code:
@Entity
@Table(name = "companyaddress")
public class CompanyAddress {

   @Id
   private EffectiveDatePrimaryKey primaryKey = new EffectiveDatePrimaryKey();
   
   @ManyToOne
   @JoinColumns ({
      @JoinColumn(name="company_id", nullable=false)
   })
   
   private Company company;


In my companyAddress:
- I only want to store the company_id.
- The effectiveDate of the company is not needed, because I only use it to store historical data

I know a ManyToOne needs a unique reference to a parent table.
I want to make the reference unique with the use of a FilterDef


Thanks in advance,
Pieter Pareit


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.