File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes one to one table structure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "one to one table structure" Watch "one to one table structure" New topic
Author

one to one table structure

shai ban
Ranch Hand

Joined: Jan 05, 2010
Posts: 177
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

Joined: Jul 14, 2010
Posts: 754

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.


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3775

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.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
 
 
subject: one to one table structure
 
Similar Threads
how to insert
implementation strategy for a simple ordering application.
BDM - cardinality of Flight - Segment relationship
Session & Entity Beans
Beginner Problem: son & parent