Hi,
There is my previous post and a post from frer on June 24 on this same subject, so it seems like its confusing to more than just myself.
Table 1 (person):
pk integer
...
Table 2 (data):
pk integer;
fk integer;
...
All the examples show a fk onetoone where the Table1 has the fk field, but my structure has the fk field on Table2. So I want the following one-to-one join but just can't figure out how to write the java:
select d.* from person p left join data d on (d.fk=
p.pk);
The code I wrote automagically added a 'fk' field to person and generated the following code:
select d.* from person p left join data d on (d.fk=
p.fk)
Code:
@Entity
@Table(name = "PERSON")
public class Person ... {
private Data data;
@Id
@OneToOne (optional=false)
@Column(name = "PERSONKEY", unique = true, nullable = false)
@NotNull
public int getPilotkey() {
...
}
@Entity
@Table(name = "DATA")
public class Data... {
private int pk;
private int fk;
private String lname;
private String fname;
private Person person;
@Id
@Column(name = "PK", unique = true, nullable = false)
@NotNull
public int getPk() {
...
}
public void setPk(int pk) {
....
}
@Id
@OneToOne (optional=false, mappedBy="data")
@JoinColumn(name = "FK", unique = true, nullable = false)
@NotNull
public int getFk() {
....
}
public void setFk(int fk) {
....
}
}
Code:
My EJBQL:
select person from Person as person join fetch person.data data
Thank you. Eric.