Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question on @IdClass and @EmbeddedID

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

I can understand that when we need composite primary keys, we go for @IdClass or @EmbeddedId. Under what scenario do we use either one of them? I mean using them is the same or different?
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any suggestions guys?
 
Sergio Tridente
Ranch Hand
Posts: 329
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jothi,

One visible difference is in the way you reference them in JQL:

- In one case, IdClass, you would do something like:


- In the other one, EmbeddedId, you would:



On the other hand, I found the use of IdClass brings some other complications as you need to define each primary key attribute in both the IdClass and the Entity, taking care of using the same name and java type. This redundancy may lead to committing more errors.


In the end, both do what they are supposed to do. So, neither of them is better than the other. It is just a matter of preference.
[ September 02, 2008: Message edited by: Sergio Tridente ]
 
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!