tags:

views:

13

answers:

1

I would like an entity "A" to map only to the primary key over a foriegn key.

class A {
   long id;
   long bId;
}

class B {
   long bId;
   ...
}

How do i do this ?

A: 

From your post it's not eaxctly clear what you want, so I'm going with what I think it is you want...

@Entity
class A {
   @Id
   long id;
   @OneTo???
   B bId;
}


@Entity
class B {
   @Id
   long bId;
   ...
}

You will need to specify the relationship between A and B and annotate the link as such. Hibernate will than link the two by generating a FK link to B's indentifier. Your tables will look something like this:

  |---------|     
  | A       |       |---------|
  |---------|       | B       |
PK|long id  |       |---------|
FK|long bId | --> PK|long bId |
  |---------|       |---------|

You could look into annotating bId with One-to-One, or One-to-Many or any of the other mappings, depending on what's applicable in you case.

Tim
Hibernate will not "automatically pick up" anything. You need to annotate B as @ManyToOne (presumably, or perhaps @OneToOne) in order for that to happen. That said, the question is indeed extremely unclear.
ChssPly76
Fixed.. (15 chars)
Tim