File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes difference between joinColumn and PrimaryKeyJoinColumni Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "difference between joinColumn and PrimaryKeyJoinColumni" Watch "difference between joinColumn and PrimaryKeyJoinColumni" New topic
Author

difference between joinColumn and PrimaryKeyJoinColumni

Senthil Kumar
Ranch Hand

Joined: Mar 13, 2006
Posts: 264
i have seen these two annotations used when we want to relate two entities.
what i want to know is how one differs from the other..


when you really want something, all the universe always conspires in your favour.<br /> <br />SCJP1.5-77%<br />SCWCD-89%
Rodrigo W Bonatto
Ranch Hand

Joined: Aug 20, 2004
Posts: 62
Hi

You can use joinColumn to define a join column in the table that references the primary key of the associated table.
PrimaryKeyJoinColumn is a little diferent and much easier when the primary key of the related entities are identical, so you do not need to specify a join column.

Regards,


SCJA, SCJP, SCJD, SCWCD, SCBCD5, SCDJWS, SCEA5
Shivani Chandna
Ranch Hand

Joined: Sep 18, 2004
Posts: 380
Usage of PrimaryKeyJoinColumn:

(1) For defining linkage to a secondary table:
@SecondaryTable(name="EMP_ADDRESS",
pkJoinColumns=@PrimaryKeyJoinColumn(name="EMP_ID"))

(2)
When no additional foreign key column in either table.In this case, @PrimaryKeyJoinColumn is used instead of an @JoinColumn annotation.


Usage of JoinColumn:

A relationship mapping where one table has a reference to another table.
i.e existence of foreign key column. In JPA its called join columns and
@JoinColumn annotation is the primary annotation used to configure these types of columns. Eg:



/** Code speaks louder than words */
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference between joinColumn and PrimaryKeyJoinColumni