My Subject class has a map collection of forms, where the key to each form is a Study object. Unfortunately, I haven't found a way to use the Map mapping for this association since the study_id key is in the form's table.
The schema looks like:
Code:
create table SUBJECT_FORM (
SUBJECT_ID INT8 not null,
FORM_ID INT8 not null,
primary key (SUBJECT_ID, FORM_ID)
);
create table FORM (
FORM_ID INT8 not null,
VERSION VARCHAR(30) not null,
STUDY_ID INT8,
primary key (FORM_ID)
);
The hibernate mapping I considered for my Subject class:
Code:
<map name="completedForms"
table="SUBJECT_FORM"
cascade="none">
<key column="SUBJECT_ID" />
<index-many-to-many
class="Study"
column="STUDY_ID"
/>
<many-to-many
class="Form"
column="FORM_ID"
/>
</map>
But to get this I would need to add the study_id in the SUBJECT_FORM relationship table to make it a ternary relationship in one table. The problem is that, each Form has a study, and a Subject has a collection of forms, so I don't want to denormalize and repeat the study_id in the relationship SUBJECT_FORM table and the FORM table.
Is there a way to specify a map key for a many-many association that is in the joined table, not the relationship table?
Any help would be GREATLY appreciated :)
Thanks,
Adam