• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

one to one table structure

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,
I am a little confused about 1-1 mapping table structure. Generally you don't need 2nd table for storing this relationship since every record of one entity will map to only single record to other entity. But I have seen different implementation on different books/articles. Some prefer to store it in a single table and some prefer to store it in two tables!!!
Earlier I thought you just need to tell hibernate about the relationship and then it will decide how many tables will be created (I am wrong). But it is us who is doing so.
Please comment about these different implementations.

Thanks.
 
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For OneToOne I do not see relationship tables often.

Just like this posts shows (JPA @OneToOne Unidirectional and Bidirectional), It just describes a relationship without a need of a Join Table.

I think it is not a good approach to have a join table because the default fetch for OneToOne is EAGER, and it would required more joins to finish when searching for an entity if you do not set as LAZY.

If you do set as Lazy it would require one more join than the regular approach.
 
Bartender
Posts: 4109
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For example a person's address may go in to a different table. But it's completely up to the application developers/designers to decide what suits best for it.

shai ban wrote:Earlier I thought you just need to tell hibernate about the relationship and then it will decide how many tables will be created (I am wrong)


You have to tell the provider (Hibernate etc...) where to store the entity.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic