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.
UNB_CLINIC_PROVIDER - TABLE B
UNB_FOCUS_REVIEW - TABLE C
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.
Joined: Aug 06, 2009
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.
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.
Joined: Aug 06, 2009
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.