-->
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.  [ 2 posts ] 
Author Message
 Post subject: creating composite foreign key
PostPosted: Tue May 16, 2006 3:34 am 
Newbie

Joined: Tue Apr 11, 2006 4:57 pm
Posts: 13
Hey,

Wondering what the correct format is to create a composite foreign key. The classes already have a composite primary key in them defined and used with the @IdClass(ActivityPk.class) and works fine on its own. If the foreign key is defined in another file Fk.java, how do I apply that definition to the Fk class in both these classes? I am not sure if I am following the correct format for creating a fk, i am trying to follow the example iin the documentation under 2.2.6. Any assistance or additional rersources in doing this correctly would be greatly appreciated.

thanks in advance,
Illusion

Code:
@Entity

@IdClass(ActivityPk.class)
public class Page implements Serializable {
   
private Integer uqid;
private Rule rule;
private Integer uqid;
private Integer vr;
private Fk fk;
   
@Id
@Column (name="uqid", length=11)
    public Integer getUqid() {
        return this.uqid;
    }

    public void setUqid(Integer uqid) {
        this.uqid = uqid;
    }

   
@Id
@Column (name="vr", length=11)
    public Integer getVr() {
        return this.vr;
    }

    public void setVr(Integer vr) {
        this.vr = vr;
    }
   
@OneToOne(cascade = CascadeType.ALL)
@JoinColumns ({
        @JoinColumn(name="fk", referencedColumnName="rule", nullable=false),  @JoinColumn(name="fk1", referencedColumnName="name", nullable=false)})   
    public Rule getRule() {
        return rule;
    }

    public void setRule(Rule rule) {
       this.rule=rule;
    }

public Fk getFk() {
     return this.fk;
    }

    public void setFk(Fk fk) {
        this.fk = fk;
    }
}


Code:
@Entity
@IdClass(ActivityPk.class)
public class Rule implements Serializable {

   
    private Integer uqid;
    private Integer vr;
    private String name;
    private String rule;
    private Fk fk;

   
@Id
@Column (name="uqid", length=11)
    public Integer getUqid() {
        return this.uqid;
    }

    public void setUqid(Integer uqid) {
        this.uqid = uqid;
    }

   
@Id
@Column (name="vr", length=11)
    public Integer getVr() {
        return this.vr;
    }

    public void setVr(Integer vr) {
        this.vr = vr;
    }

   

@Column (name="name", length=80, nullable=false)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

   
@Column (name="rule", length=255, nullable=true)
    public String getRule() {
        return this.rule;
    }

    public void setRule(String rule) {
        this.rule = rule;
    }

   

@OneToOne
@JoinColumns ({@JoinColumn(name="fk", referencedColumnName="rule", nullable=false),@JoinColumn(name="fk1",referencedColumnName="name", nullable=false)
    })   
public Page getPage() {
     return this.page;
    }

    public void setPage(Page page) {
        this.page = page;
    }

public Fk getFk() {
     return this.fk;
    }

    public void setFk(Fk fk) {
        this.fk = fk;
    }
}



Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 6:45 am 
Beginner
Beginner

Joined: Fri Apr 28, 2006 3:04 am
Posts: 22
Location: Amsterdam
Read this thread:

http://forum.hibernate.org/viewtopic.ph ... 53&start=0

and this blog:

http://java-aap.blogspot.com/2006/04/hi ... html#links


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

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.