aspose file tools*
The moose likes Object Relational Mapping and the fly likes Problem in composite key mapping in eclipselink Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Problem in composite key mapping in eclipselink" Watch "Problem in composite key mapping in eclipselink" New topic
Author

Problem in composite key mapping in eclipselink

syruss kumar
Ranch Hand

Joined: Jul 23, 2009
Posts: 97
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

All search starts with beginner's luck and all search ends with victor's severly tested.
Arunsanjay Jayarathanam
Greenhorn

Joined: Oct 17, 2010
Posts: 5
Can you give us more details about the error that occurs??


Sanjay
syruss kumar
Ranch Hand

Joined: Jul 23, 2009
Posts: 97
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

Joined: Oct 01, 2007
Posts: 553
> @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).


TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Arunsanjay Jayarathanam
Greenhorn

Joined: Oct 17, 2010
Posts: 5
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

Joined: Jul 23, 2009
Posts: 97
Thanks a lot sanjay and james.It works .thanks a lot for the link and suggestion.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem in composite key mapping in eclipselink