• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Annotations doubt

 
Aditya Vasudeva
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 389
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
 
Aditya Vasudeva
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You for the clarification, Anu.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic