I have a situation where I have a one-to-one mapping, but I have to use a constrained many-to-one.
table A
- a_id
table B (has a composite id with the following columns)
- a_id
- b_type
table C (has a composite id with the following columns)
- a_id
- c_type
I just added a mapping for table B, which has a relation to table C. The *_type for each table doesn't really matter except for the fact that they are part of a composite id for each table. I have successfully used the following mapping to work with this relationship.
Code:
...
<class name="B">
...
<many-to-one name="c"
class="foo.C"
cascade="all"
unique="true"
insert="false"
update="false">
<column name="THIS_IS_IGNORED_1"/>
<column name="THIS_IS_IGNORED_2"/>
</many-to-one>
...
</class>
The above mapping mysteriously works and I'm wondering why.
1. I originally thought the column names would have to match up to a table, but this isn't the case. I can make the column names whatever I want. It doesn't matter what the values are.
2. Hibernate DOES complain if I remove one of the column tags. This is because it wants the same number of column tags as there are columns in the primary key of the other table.
3. Hibernate DOES look at the names of the columns if I remove the insert="false" update="false".
Can someone explain why this works? Also, I don't see much domentation on the insert and update values. Can someone explain the behavior of these attributes or point me to the documentation?
Thanks in advance,