Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Problem in composite key mapping in eclipselink

 
Ranch Hand
Posts: 108
  • 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
 
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: 108
  • 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.



 
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: 108
  • 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.
 
F is for finger. Can you stick your finger in your nose? Doesn't that feel nice? Now try this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!