-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: HELP! problems with hashCode()
PostPosted: Wed Jan 14, 2004 12:05 pm 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
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>


MpRequisitosQual
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.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>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 12:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
This has been discussed here many times, for example here: http://forum.hibernate.org/viewtopic.php?t=926896&highlight=equals+hashcode


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.