Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

one to one table structure

 
shai ban
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.
 
Hebert Coelho
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.
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic