Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) 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
Sheriff
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 .
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!