• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

one to one table structure

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
  • 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
  • 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: 4107
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic