I'm using Hibernate 2.1.1.
I want to insert a
Mp with two
MpRequisitosQual in it's "Set".
But when I do this, it only inserts the first
MpRequisitosQual!
By the generated code (hbm2java), I see that the equality between two objects is made via there "id". And when I add the second
MpRequisitosQual to the "Set", he's discarded because there's already an object with the same id (which is
null at the time).
The
hashCode() is responsible for this "id" test, right?
Please help. I really need to solve this. It's urgent.
Thanks in advance.
----------------------------------------
Mapping files (generated with R3)
----------------------------------------
Mp
Code:
<?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>
<!--
Created by Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="vo.Mp"
table="mp"
>
<id
name="id"
type="long"
column="id"
>
<generator class="increment" />
</id>
<property
name="referencia"
type="java.lang.String"
column="referencia"
not-null="true"
length="-1"
/>
<!-- associations -->
<!-- bi-directional one-to-many association to MpRequisitosQual -->
<set
name="mpRequisitosQuals"
lazy="true"
inverse="true"
cascade="save-update"
>
<key>
<column name="mp_fk" />
</key>
<one-to-many
class="vo.MpRequisitosQual"
/>
</set>
</class>
</hibernate-mapping>
MpRequisitosQualCode:
<?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>
<!--
Created by Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="vo.MpRequisitosQual"
table="mp_requisitos_qual"
>
<id
name="id"
type="long"
column="id"
>
<generator class="increment" />
</id>
<property
name="designacao"
type="java.lang.String"
column="designacao"
not-null="true"
length="-1"
/>
<!-- associations -->
<!-- bi-directional many-to-one association to Mp -->
<many-to-one
name="mp"
class="vo.Mp"
not-null="true"
>
<column name="mp_fk" />
</many-to-one>
</class>
</hibernate-mapping>