• Post Reply Bookmark Topic Watch Topic
  • New Topic

Annotions doubt  RSS feed

 
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 .
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!