-->
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.  [ 9 posts ] 
Author Message
 Post subject: Inifinite loop loading objects
PostPosted: Thu Oct 30, 2003 3:32 pm 
Beginner
Beginner

Joined: Thu Oct 09, 2003 3:42 pm
Posts: 22
Using 2.1 beta 4

Hi all, I have a system with three classes: Communications, Segments and SegmentResults. Each Communication has a list of Segments and eache Segment has a list of SegmentResults. Both Segments and SegmentResults have references back to their "owing objects" (mapping file follows)

When I load a Communication e.g
Code:
Communication c = (Communication)sess.load(Communication.class,"BBBBJ3R3BBBN");
everything works as I want it too.

But if I load a Segment e.g.
Code:
Segment c = (Segment)sess.load(Segment.class,"BBBBJ3R4BBJR");
The system appears to go into an infinite loop loading the segment over and over.

Any ideas what might be causing this?

Thanks, Marc

Code:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
    <class name="com.teradata.crm.tracer.examples.Folder.entity.Communication" table="IOS_ECAMP">
        <id name="ecampId" type="java.lang.String">
            <column name="ECAMP_ID" length="12"/>
            <generator class="com.teradata.crm.tracer.examples.Folder.entity.IdGenerator.KhariGenerator"/>
        </id>
        <set name="segmentsHibernate" table="IOS_ECAMP_X_SEG" inverse="true" lazy="false" outer-join="true" cascade="save-update">
            <key column="ECAMP_ID"/>
            <one-to-many class="com.teradata.crm.tracer.examples.Folder.entity.Segment"/>
        </set>
        <!-- other properties -->
    </class>
    <class name="com.teradata.crm.tracer.examples.Folder.entity.SegmentResult" table="IOS_ECAMP_SEG_RES">
        <composite-id name="objectId" class="com.teradata.crm.tracer.examples.Folder.entity.PK.SegResPk">
            <key-many-to-one name="segment" class="com.teradata.crm.tracer.examples.Folder.entity.Segment" column="SEG_ID"/>
            <key-property name="custLevelCode" column="CUST_LEV_CD" type="java.lang.String"/>
        </composite-id>
        <!-- other properties -->
    </class>
    <class name="com.teradata.crm.tracer.examples.Folder.entity.Segment" table="IOS_ECAMP_X_SEG">
        <id name="segId" type="java.lang.String">
            <column name="SEG_ID" length="12"/>
            <generator class="com.teradata.crm.tracer.examples.Folder.entity.IdGenerator.KhariGenerator"/>
        </id>
        <set name="resultsHibernate" table="IOS_ECAMP_SEG_RES" inverse="true" lazy="false" outer-join="true" cascade="delete">
            <key column="SEG_ID"/>
            <one-to-many class="com.teradata.crm.tracer.examples.Folder.entity.SegmentResult"/>
        </set>
        <many-to-one name="communication" column="ECAMP_ID" class="com.teradata.crm.tracer.examples.Folder.entity.Communication" outer-join="true"/>
      <!-- other properties -->
    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 30, 2003 5:52 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is a FAQ! Implement equals()/hashCode() properly for the composite id.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 30, 2003 5:59 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Does this http://www.hibernate.org/116.html#A19, that http://www.hibernate.org/hib_docs/reference/html_single/#or-mapping-s1-4b and that http://www.hibernate.org/hib_docs/reference/html_single/#components-s2-3 help ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2003 10:33 am 
Beginner
Beginner

Joined: Thu Oct 09, 2003 3:42 pm
Posts: 22
I was a little bit confused on this point. I am using a composite key for the SegmentResult class and overrode the equals and hashCode methods in the key class (SegResPK). Do I also need to overide equals and hashCode in the SegmentResults class?

Thanks for all of you help.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2003 10:58 am 
Beginner
Beginner

Joined: Thu Oct 09, 2003 3:42 pm
Posts: 22
I'm starting to think that this problem does not have anything to do with hashCode and equals method. I put breakpoints in my implementation of these methods in the SegmentResult and SegResPK class and none of the methods ever get executed.

Any other ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2003 12:58 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You have table attribute on a set representing a one-to-many relationship.

This is useless since hibernate can gess it from the one-to-many class.
May be the cause of your pb ?

Quote:
A one to many association links the tables of two classes directly, with no intervening collection table. (This implements a one-to-many relational model.)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 31, 2003 9:40 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Btw, what is the meaning of inverse="true" for the resultsHibernate set?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 01, 2003 1:43 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
There are some recent threadd on this topic.
[url]http://forum.hibernate.org/viewtopic.php?t=925100[/url
http://forum.hibernate.org/viewtopic.php?t=925201&highlight=inverse

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 03, 2003 11:18 am 
Beginner
Beginner

Joined: Thu Oct 09, 2003 3:42 pm
Posts: 22
I ended up removing the key-many-to-one from the SegmentResult composite key and replaced it with the String property for the id of the object that the key-many-to-one was referring to.

This isn't the most ideal solution for us but it works ... and thats always a good thing.

I'll probably play around with this a little bit more down the road but I need to move on for now.

Emmanuel, thanks for your help.

-marc


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.