I have following table,
Code:
Table (
col1 [PK, FK1, FK2],
col2 [PK]
col3 [FK2]
col4
col5
)
The primary key for table is composite. It is mapped using <composite-id> element in mapping file.
1. PK Mapping
Code:
<composite-id>
<key-property column="col1" />
<key-property column="col2" />
</composite-id>
2. FK1 mapping
Now col1 is foreign key so it is mapped again.
Code:
<many-to-one class="SomeClass" column="col1" />
3. FK2 mapping
There is also foreign key to composite primary key. It is mapped again,
Code:
<many-to-one ...>
<column name="col1" />
<column name="col3" />
</many-to-one>
Now col1 is mapped thrice and I get repeated column mapping exception. I can mark FK1 mapping as update='false' and insert='false' without any impact.
But if I mark FK2 mapping as update='false' and insert='false' then the col3 value is not inserted in DB and I lose the foreign key link. If I remove update='false' and insert='false' then I get mapping problem.
Is there any workaround for this issue? I cannot change the table structure also we are not using annotations.
Is it possible to define update='false' and insert='false' at column level, so that I can mark col1 in FK2 mapping.