I have two classes related by an one-to-one relationship using the following code:
Code:
<class name="PessoaTO" table="pessoa">
<id
name="id"
type="java.lang.Long"
column="id"
>
<generator class="native"/>
</id>
<version column="timestamp" name="timestamp" type="java.sql.Timestamp" />
<one-to-one name="codConjuge" constrained="false" outer-join="false" class="com.sib.transobject.pessoa.ConjugeTO" />
Code:
<class name="ConjugeTO" table="conjuge">
<id
name="id"
type="java.lang.Long"
column="id"
>
<generator class="foreign">
<param name="property">codPessoa</param>
</generator>
</id>
<one-to-one name="codPessoa" constrained="true" outer-join="auto" class="com.sib.transobject.pessoa.PessoaTO"/>
To save or update a line in the conjuge table i'm doing this:
Code:
PessoaTO pessoaTO = (PessoaTO)DAOFactory.getPessoa().load(new Long(32));
pessoaTO.setCodConjuge(conjugeTO);
conjugeTO.setCodPessoa(pessoaTO);
ConjugeBO conjugeBO = new ConjugeBO();
conjugeBO.saveOrUpdate(conjugeTO);
When there isn't a line in Conjuge table with id=32 it works fine. The line is created with the same id as the person. When i try to load a Conjuge it works as well. But when this line ( Conjuge with field id 32 ) already exists in the database insted of updating the conjuge table with the new values i'm getting a
NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 32
Anybody know how to make this work?