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;
}
}