• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@IdClass and @EmbeddedId

 
rani vini
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone tell what is the difference between @IdClass and @EmbeddedId?

Thanks in advance
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a Compound Primary Key Class using the @Embeddable tag:





(From this Hibernate/JPA Tutorial)

Later, a class can use that compound key:



ith the @IdClass annotation, you don't declare an instance variable of type CompoundKey, but instead, just define instance variables for each of the primary key fields. You then mark the corresponding getter tags with standard @Id annotations.



Here's a little bit more detailed explaination about mapping compound primary keys with Hibernate and JPA:

Mapping Composite Keys with the Java Persistence API (JPA)

-Cameron McKenzie



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic