Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in composite key mapping in eclipselink

 
syruss kumar
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Im newbie to eclipse link .im trying to use IdClass annotation for composite primary key mapping but its throwing error.i have googled and couldnt found enough details regarding this.

Company
------------
companyid(pk)
companyname
companyaddress

Employee
------------
empid(pk)
empname
empage
companyid(pk)


here is the code





Please suggest me where i did mistake in the code.

Thanks in advance
 
Arunsanjay Jayarathanam
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you give us more details about the error that occurs??
 
syruss kumar
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sanjay,

Thanks for your reply.Here is the exception i got while execute the code..




Please suggest me where i did wrong.



 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> @IdClass(Company.class)

This is wrong. Company is your other entity class, it is not an id class. You need an EmployeeID class that has the same fields as your employee id (as the error states).
 
Arunsanjay Jayarathanam
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe your intention is to use the Company Id as one of the properties to uniquely identify an employee.
In order to do that , you need to have an IdClass composite of the properties ( empid, companyid) that uniquely
identify the employee in a separate class; and Have a relationship with the Company entity in the
Employee entity and as well use it as @Id property. Something like ,


(Note : the above code might not be the exact code, but something in the same lines. refer to the below link for details)
Refer to JPA Composite Primary Keys, for detailed explanation.

Go through the JPA 2.0 examples in the above link
 
syruss kumar
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot sanjay and james.It works .thanks a lot for the link and suggestion.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic