• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

about one to one

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic