gavin wrote:
In HIbernate3 you can use:
<list name="timePeriods">
<key column="TP_TU_ID" not-null="true"/>
<index column="TP_ORDER"/>
<one-to-many class="TimePeriod"/>
</list>
And set the other end of the relationship insert="false" update="false"
The biggest difference I see in this and the mapping that I had posted, is that inverse=true is removed. Was that the idea ? If that is the case, I can remove the inverse attribute from my mapping also - without adding not-null="true" to <key> and not adding insert=false, update=false to many-to-one.
This is how the other side of association looks like in TimePeriod class
<many-to-one name="timeUnit"
class="TimeUnit"
column="TP_TU_ID"
not-null="true" />
I tried out the suggestion but it creates following sql
Hibernate: insert into TIME_UNITS (VERSION, NAME, TU_ID) values (?, ?, ?)
Hibernate: insert into TIME_PERIODS (VERSION, TP_TU_ID, TP_ORDER, TP_ID) values (?, ?, ?, ?)
Hibernate: insert into TIME_PERIODS (VERSION, TP_TU_ID, TP_ORDER, TP_ID) values (?, ?, ?, ?)
Hibernate: update TIME_PERIODS set TP_TU_ID=?, TP_ORDER=? where TP_ID=?
Hibernate: update TIME_PERIODS set TP_TU_ID=?, TP_ORDER=? where TP_ID=?
which is same as if I just remove inverse=true from my current mapping.
The question is should I remove the inverse? In that case hibernate would think the two associations are different and do the INSERT for one and UPDATE for another, for every timeperiod object I have. Is that good?