-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: What's diff bet using @JoinColumn and @PrimaryKeyJoinColumn
PostPosted: Sat Jul 12, 2008 12:05 am 
Newbie

Joined: Tue Oct 02, 2007 3:49 am
Posts: 17
Dear All,

In one to one relationship, you can use @JoinColumn or @PrimaryKeyJoinColumn to represent the relationship. Can anyone tell me that which situation should be used in this 2 ways? Thanks

Best Rdgs
Ellis


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 14, 2008 5:44 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi Ellis,

the difference is on how the relationship between the two entities is persisted. Using @JoinColumn a foreign key column will be used within the entity defining the annotation. Using @PrimaryKeyJoinColumn no additional column is needed since both entities share the same primary key. There is also a third option using @JoinTable.

The question regarding which option to choose is a matter of taste. If you have the freedom to start from scratch I would go with the default (JoinColumn). The other options allow you to integrate for example with existing databases where the schema cannot be modified.

Have a look at the online documentation: http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/#entity-mapping-association

--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.