-->
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: 2 recent posts on this subject - fk in 2nd table
PostPosted: Fri Jun 26, 2009 8:24 pm 
Newbie

Joined: Mon Jun 22, 2009 8:41 am
Posts: 3
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.


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.