• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

OneToOne mapping with 2 composite keys using JPA

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
TableA has a 3 column composite primary key, TableB has a 2 column composite key primary key (these 2 columns are in TableA) and TableC
has a single column primary key but has a composite foreign key from TableB.

This is an inherited table structure which I cannot change.

TableA 1:1 TableB
TableB M:1 TableA
TableB 1:M TableC
TableC M:1 TableB

UNB_NETWORK_CLINIC_PROVIDER - TABLE A
NETWORK_NO (PK)
CLINIC_NO (PK)
PROVIDER_NO (PK)
DELTA_BEGIN_DATE
DELTA_END_DATE

UNB_CLINIC_PROVIDER - TABLE B
CLINIC_NO (PK)
PROVIDER_NO (PK)
DELTA_BEGIN_DATE
DELTA_END_DATE

UNB_FOCUS_REVIEW - TABLE C
FOCUS_REVIEW_NO (PK)
PROVIDER_NO(FK)
CLINIC_NO(FK)
PROC_NO_FROM
PROC_NO_TO

I have used OneToMany JPA annotation to model the mapping between TableB and TableC using the composite key in the mappedBy attribute.
Please see code below in namely UnbClinicProv.java and UnbFocusReview.java. This worked when the composite key of TableB was a foreign key in TableC.

I tried (the same thing I thought) for the OneToOne mapping in UnbNetworkClinicProvider.java but this gives the error below.

Is it possible to model the OneToOne mapping between TableA and TableB using JPA annotations when the composite key of TableB is not a
full foriegn key in TableA?
If yes how?

Please see below for the tables, code snippets and error I get;

Any help/comments appreciated.

Error:


UnbClinicProv.java


UnbFocusReview.java


UnbNetworkClinicProvider.java


NetworkClinicProviderCompoundKey.java


ClinicProvCompoundKey.java
 
Donnacha Lehane
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I try and change my mapping to link through the foreign key columns rather than using the composite key I also get an error.
Again I'm not sure if this is possible and not sure which option I should be investigating further.

If anyone has any ideas whether I am on the right road on not please let me know.

Error:


UnbNetworkClinicProvider.java


UnbClinicProv.java
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, the exceptions are pretty good in their definition. Telling you a property is not mapped means just that - you have an instance variable in a class that has no mapping.

Telling you the db doesn't have the same number of columns as the compound primary key is pretty good too.

How were the mappings done? Did you reverse engineer or do it yourself? Sometimes just doing one class at a time isn't a bad idea either.

-Cameron McKenzie
 
Donnacha Lehane
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.

I did the mappings myself and therin lies my problem. I got the relationships between the tables incorrect. The mapping I was having trouble with was between TableA and TableB. This is in fact a M:1 relationship and when I changed it to such it worked. Please see my working code below.

BTW, 'Hibernate made easy' is a great help, thanks.

UnbNetworkClinicProvider.java
 
Catch Ernie! Catch the egg! And catch this tiny ad too:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic