| Author |
about one to one
|
David Wong
Greenhorn
Joined: Dec 31, 2007
Posts: 15
|
|
are there two strategies of mapping for <one-to-one/> ?one is primary key mapping strategy other is foreign key mapping strategy.what's the advantage in each of them? if i have a construction of db below: table a id int primary key name varchar table b id int primary key a_id int foreign key(a_id) references a(id) how could we use the two strateies to get one a to one b.what are the differences? thanks very much!!
|
Bitter Java For Better Life.
|
 |
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Joined: Aug 26, 2006
Posts: 4967
|
|
I'm not sure how you're using the term one-to-one here? To map one table to one class, is fairly straight forward. You can just use the @Entity annotation: Mapping One Class to One Table But you mentioned using a shared primary key? So this would be two classes to one table? You can use the @Embedded and @Embeddable annotations to accomplish this: Mapping Two Classes to One Table Using Hibernate and JPA Annotations But then you mention foreign keys? So you may have two tables related by a foreign key mapping to one class? In this case you're looking at using the @SecondaryTable annotation Mapping One Class to Two Database Tables using Hibernate and JPA Is that what you were getting at? -Cameron McKenzie
|
Author of Hibernate Made Easy, What is WebSphere???, JSF 2.0 Made Easy and the SCJA Certification Guides
|
 |
 |
|
|
subject: about one to one
|
|
|