File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Annotations doubt 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 "Annotations doubt" Watch "Annotations doubt" New topic

Annotations doubt

Aditya Vasudeva
Ranch Hand

Joined: May 27, 2008
Posts: 76
I am reading EJB3 in action.

I could not understand the difference between the 2 annotations: @JoinColumn and @PrimaryJoinColumn regarding O-R mapping.

What is the difference in the following 2 snippets of code:

Code snippet 1: (Using @JoinColumn)

Code snippet 2: (Using @PrimaryKeyJoinColumn)
Nikhil Jain
Ranch Hand

Joined: May 15, 2005
Posts: 389
@JoinColumn is used to join any column in 2 tables, Where as @PrimaryKeyJoinColumn it joins based on the primary keys

For Example

Say you have 2 tables
Employee - id, name, age
Bank - id, acct

So in this case if you want to join these two tables based on primary key, we could use @PrimaryKeyJoinColumn.

As such there is not much of a difference. Both could be used

SCJP 1.4, SCWCD 1.4, SCBCD 1.5, TOGAF 9, Comptia Cloud+
Aditya Vasudeva
Ranch Hand

Joined: May 27, 2008
Posts: 76
Thank You for the clarification, Anu.
I agree. Here's the link:
subject: Annotations doubt
It's not a secret anymore!