-
1. Re: Can not use PrimaryKeyJoinColumns
pimpf Mar 15, 2006 8:20 AM (in response to adver11)The PrimaryKeyJoinColumn annotation is used to join the primary table of an entity subclass in the JOINED mapping strategy to the primary table of its superclass; it is used with a SecondaryTable annotation to join a secondary table to a primary table; and it may be used in a OneToOne mapping in which the primary key of the referencing entity is used as a foreign key to the referenced
entity.
The PrimaryKeyJoinColumn annotation specifies a primary key column that is used as a foreign key to join to another table.
Example (from the spec):
public class EmpPK {
public Integer id;
public String name;
}
@Entity
@IdClass(com.acme.EmpPK.class)
public class Employee {
@Id Integer id;
@Id String name;
@OneToOne
@PrimaryKeyJoinColumns({
@PrimaryKeyJoinColumn(name="ID",
referencedColumnName="EMP_ID"),
@PrimaryKeyJoinColumn(name="NAME",
referencedColumnName="EMP_NAME")})
EmployeeInfo info;
...
}
@Entity
@IdClass(com.acme.EmpPK.class)
public class EmployeeInfo {
@Id @Column(name="EMP_ID")
Integer id;
@Id @Column(name="EMP_NAME")
String name;
...
}
In your case you can use @JoinColumns like this:
@ManyToOne
@JoinColumns({
@JoinColumn(name="DESK_ZONE",referencedColumnName="ZONE"),
@JoinColumn(name="DESK_ID", referencedColumnName=="ID")
})
private Chkin_desk CHKIN_DESK;
Or better take a look at the spec:
9.1.6 JoinColumn Annotation
and
9.1.7 JoinColumns Annotation -
2. Re: Can not use PrimaryKeyJoinColumns
adver11 Mar 15, 2006 9:12 PM (in response to adver11)thank pimpf.
I test it like this:
EmpPK.javapublic class EmpPK { public Integer id; public String name; }
EmployeeInfo.java@Entity @IdClass(EmpPK.class) public class EmployeeInfo { @Id @Column(name="EMP_ID") Integer id; @Id @Column(name="EMP_NAME") String name; ... }
Employee.java@Entity @IdClass(EmpPK.class) public class Employee { @Id Integer id; @Id String name; @OneToOne @PrimaryKeyJoinColumns ({ @PrimaryKeyJoinColumn(name="ID", referencedColumnName="EMP_ID"), @PrimaryKeyJoinColumn(name="NAME", referencedColumnName="EMP_NAME") }) EmployeeInfo info; ... }
the Employee.java shows that have a problem about @PrimaryKeyJoinColumns.
the problem is : The annotation @PrimaryKeyJoinColumns is disallowed for this location
I make this Example within JBoss-4.0.4RC1, and using JBossIDE-1.5.1.GA.
I think it's a bug.