• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JPA with onetomany between two tables, each having compound primary keys

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone please provide a working example of how to map with JPA, the following situation. One to many between two tables each having compound primary keys as follows:

We have searched everywhere and cannot find any examples using compound keys in both tables.

Here is what I have thus far.



 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi and welcome to the Javaranch.

Please UseCodeTags when posting code. It will highlight your code and make it much easier to read. It probably will also increase the number of people helping you. I've added them for you since you are new and so that you can see the difference.
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code looks fine. What issue are you having?

You could also use an IdClass instead of the EmbeddedId, this would let you put the @Id on the ManyToOne and avoid the duplicate mapping of the foreign keys.
 
Phil Cuccatti
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am receiving the following error:

Initial SessionFactory creation failed.org.hibernate.MappingException: Unable to find column with logical name: SUPPLIER_PART_1_ID_PK1 in org.hibernate.mapping.Table(CARE.PRODUCTS_STUPID) and its related supertables and secondary tables
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Phil,

This is what I read in API for JoinTable.


This annotation is used in the mapping of associations. It is specified on the owning side of a many-to-many association, or in a unidirectional one-to-many association.



But, your mapping is bi-directional. I think, JoinColumns must be used to define composite PK mapping.

I am no expert in Hibernate. Expert opinion welcome.
reply
    Bookmark Topic Watch Topic
  • New Topic