It is a quite essential 1:n relationship. A partner has n contracts. I just have an unidirectional relationship from contract to partner.
<hibernate-mapping package="com.hdb.model">
<class name="Contract" table="Contract">
<id name="id" column="ID" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">CONTRACT_S</param>
</generator>
</id>
<timestamp name="updateTimestamp" column="UPDATE_TIMESTAMP"></timestamp>
<property name="type" column="TYPE" type="java.lang.Byte" />
......
<many-to-one name="partner" column="PA_ID" class="Partner" cascade="none" />
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping package="com.hdb.model">
<class name="Partner" table="Partner">
<id name="id" column="ID" type="java.lang.Long">
<generator class="sequence">
<param name="sequence">PArtner_S</param>
</generator>
</id>
<timestamp name="updateTimestamp" column="UPDATE_TIMESTAMP"></timestamp>
<property name="name" column="NAME" type="java.lang.String" not-null="true" />
......
</class>
</hibernate-mapping>
I didn't specified any unsaved-value, which should be null in the default case. I had similar mapping done without problem. But this time, I always run into this TransientObjectException. The programm looks like:
open a session, load a contract and return it, close session. Use the reference returned (which is detached now), change an attribute, open a session, update it, commit, close session. (Everything is fine until now). Use the same reference, change another attribute, open a session, update it, commit and close session. bang, an exception is thrown, complaining that the related partner object is transient.
The situation doesn't change, when I put unsaved-value="null" for the partner object.
Any clue?
|