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 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
Author

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: 385
@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
Aditya Vasudeva
Ranch Hand

Joined: May 27, 2008
Posts: 76
Thank You for the clarification, Anu.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Annotations doubt
 
Similar Threads
Issues with @PrimaryKeyJoinColumn
OneToOne Bidirectional Using @PrimaryKerJoinColumn
onetoone unidirectional relationship problem
Getting error message - chapter 9 of ejb 3 in action using glassfish server 2.1
Question about the type of JoinColumn.