This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Annotions 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 what the @IdClass and the @EmbeddedId did. Although I understood that @Id was used to identify an entity's uniqueness using a single identity.

Could you please help me by explaining the above annotations using an example for proper understanding.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Aditya Vasudeva:


I could not understand what the @IdClass and the @EmbeddedId did. Although I understood that @Id was used to identify an entity's uniqueness using a single identity.



A entity's id (primary key) can be composed of more than one column. Let's consider a case where your entity's id is composed of 2 columns named 'A' and 'B'. In such a scenario, you create a separate class (the IdClass) to map the 2 columns in the IdClass and then use this class as the composite-key on the entity. The @EmbeddedId does the same thing. I usually refer to this whenever i need to know the usage of a JPA annotation. Here's the @IdClass usage and here's the @EmbeddedId .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic