Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I have a child table when the parent has a composite key

 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to model a set of tables that are very poorly designed. The problem is that I have a table with a composite key, and this table has some child tables. So, the tables look like this



There is an Instrument table with a composite PK(instrument id and batchID) and a Payment table with a composite PK(instrument ID, batch ID and paymentDate) There is FK relationship between Payment and Instrument on instrumentID and batchID. For an Instrument there can be multiple Payments

My first inclination is to change the table to add proper sequence generated IDs, but doing so would impact a lot of legacy code. I might be able to do it, but if I can't, I wanted to see if there are any options to model the table as is in JPA

What I have now is this



The problem is I can;t figure out how to put the Join annotations. I wanted to put OneToMany on Instrument.payments and ManytoOne on PaymentPK.instrument. However, how do I put multiple column names in the relationship?
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do something like:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic