I am using Hibernate 3.2. I have a two tables Test, Query and QueryPart with a one-to-one mapping between Test and Query as below and one-to-many mapping between Query and QueryPart as below. However, when I try to do an update on Test, there is a new entry inserted into the Query and QueryParts table, instead of doing an update. Why would that be and how would I fix that?
Code:
<hibernate-mapping>
<class name="com.test.Test"
mutable="false"
table="TEST">
<cache usage="nonstrict-read-write"/>
<id name="id" column="shared_id" access="field">
<generator class="native"/>
</id>
<many-to-one name="testQuery" access="property" column="query_id"
foreign-key="query_id_fk"
cascade="save-update,delete" unique="true"
not-null="true"/>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping>
<class name="com.test.Query" table="QUERY">
<cache usage="nonstrict-read-write"/>
<id name="id" column="QUERY_ID">
<generator class="native"/>
</id>
<list name="queryParts" table="QUERY_PARTS" cascade="all-delete-orphan" access="field">
<cache usage="nonstrict-read-write"/>
<key column="QUERY_ID" foreign-key="QUERY_ID_FK" not-null="true"/>
<list-index column="QUERY_INDEX"/>
<one-to-many class="com.company.QueryPart"/>
</list>
</class>
</hibernate-mapping>