-->
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.  [ 12 posts ] 
Author Message
 Post subject: Infinite Loop whith outer-join in bidirectional association
PostPosted: Thu Aug 26, 2004 9:41 am 
Newbie

Joined: Thu Aug 26, 2004 8:50 am
Posts: 6
Hibernate version:2.1.4

Oracle 9.2

Hi all,

I’ve got a parent-child bi-directional association where the child’s key is composite (Child ID ,Parent ID).
Everyhing works as expected whatever lazy is set to true or false as long as outer-join is not set to true.

When I add outer-join =”true”, I can save a newly instanciated parent with or without childs but when I try to read it again I get caught in an infinite loop .

I checked my hashcode() and equals() methods on each concerned class and even added log on it but these are not called in this loop. Moreover, it works perfectly without the outer- join option.

Any idea here ?


Here are my mapping files
parent :
Code:
<class
        name="lm.met.vo.Contrat"
        table="ccd_contrat"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="numeroContrat"
            column="NUMLMD"
            type="java.lang.String"
        >
            <generator    class="lm.fwk.persistance.hibernate.StringSequenceGenerator">
                <param name="sequence">CONTRAT_SEQ_ID</param>
            </generator>
        </id>

        <property
            name="idProduit"
            type="java.lang.String"
            update="true"
            insert="true"
            column="TYPCON"
        />

        <property
            name="libelleCommercial"
            type="java.lang.String"
            update="true"
            insert="true"
            column="LIBCON"
        />

       <set
            name="ctxAdh"
            lazy="true"
            inverse="true"
            cascade="all-delete-orphan"
            sort="unsorted"
           outer-join="true"
        >

              <key
                  column="NUMLMD"
              />

              <one-to-many
                  class="lm.met.vo.ContexteAdherente"
              />
        </set>



    </class>

Child
Code:
<hibernate-mapping>
    <class
        name="lm.met.vo.ContexteAdherente"
        table="ccd_adherente"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <composite-id
            name="key"
            class="lm.met.vo.ContexteAdherenteKey"
            unsaved-value="any"
        >

                     <key-property
                        name="numPerAdherente"
                        type="java.lang.String"
                        column="NUMPER"
                />

                    <key-many-to-one
                        name="contrat"
                        class="lm.met.vo.Contrat"
                        column="NUMLMD"
                    />

        </composite-id>

        <property
            name="dateEffet"
            type="java.util.Date"
            update="true"
            insert="true"
            column="EFFADE"
        />

    </class>



user code:

Code:
Contrat c=(Contrat)session.get(Contrat.class,numeroContrat);



Debug level Hibernate log excerpt while looping : 2loops

Code:


15:20:41,274?DEBUG BatcherImpl:196 - about to open: 3 open PreparedStatements, 3 open ResultSets
15:20:41,274?DEBUG SQL:237 - select contrat0_.NUMLMD as NUMLMD2_, contrat0_.DATEFF as DATEFF2_, contrat0_.DATSIG as DATSIG2_, contrat0_.DEVISE as DEVISE2_, contrat0_.INDEXT as INDEXT2_, contrat0_.TYPCON as TYPCON2_, contrat0_.LIBCON as LIBCON2_, contrat0_.NUMLML as NUMLML2_, contrat0_.NUMPER as NUMPER2_, contrat0_.NUMGEN as NUMGEN2_, etat1_.NUMLMD as NUMLMD0_, etat1_.DATEFF as DATEFF0_, etat1_.LIBETA as LIBETA0_, etat1_.LIDCRE as LIDCRE0_, ctxadh2_.NUMPER as NUMPER__, ctxadh2_.NUMLMD as NUMLMD__, ctxadh2_.NUMPER as NUMPER1_, ctxadh2_.NUMLMD as NUMLMD1_, ctxadh2_.EFFADE as EFFADE1_, ctxadh2_.LIDCRE as LIDCRE1_, ctxadh2_.DEVISE as DEVISE1_, ctxadh2_.DATCRE as DATCRE1_ from ccd_contrat contrat0_ left outer join ccd_etat etat1_ on contrat0_.NUMLMD=etat1_.NUMLMD left outer join ccd_adherente ctxadh2_ on contrat0_.NUMLMD=ctxadh2_.NUMLMD where contrat0_.NUMLMD=?
Hibernate: select contrat0_.NUMLMD as NUMLMD2_, contrat0_.DATEFF as DATEFF2_, contrat0_.DATSIG as DATSIG2_, contrat0_.DEVISE as DEVISE2_, contrat0_.INDEXT as INDEXT2_, contrat0_.TYPCON as TYPCON2_, contrat0_.LIBCON as LIBCON2_, contrat0_.NUMLML as NUMLML2_, contrat0_.NUMPER as NUMPER2_, contrat0_.NUMGEN as NUMGEN2_, etat1_.NUMLMD as NUMLMD0_, etat1_.DATEFF as DATEFF0_, etat1_.LIBETA as LIBETA0_, etat1_.LIDCRE as LIDCRE0_, ctxadh2_.NUMPER as NUMPER__, ctxadh2_.NUMLMD as NUMLMD__, ctxadh2_.NUMPER as NUMPER1_, ctxadh2_.NUMLMD as NUMLMD1_, ctxadh2_.EFFADE as EFFADE1_, ctxadh2_.LIDCRE as LIDCRE1_, ctxadh2_.DEVISE as DEVISE1_, ctxadh2_.DATCRE as DATCRE1_ from ccd_contrat contrat0_ left outer join ccd_etat etat1_ on contrat0_.NUMLMD=etat1_.NUMLMD left outer join ccd_adherente ctxadh2_ on contrat0_.NUMLMD=ctxadh2_.NUMLMD where contrat0_.NUMLMD=?
15:20:41,274?DEBUG BatcherImpl:241 - preparing statement
15:20:41,290?DEBUG StringType:46 - binding '358        ' to parameter: 1
15:20:41,290?DEBUG Loader:197 - processing result set
15:20:41,290?DEBUG StringType:68 - returning '358        ' as column: NUMLMD0_
15:20:41,306?DEBUG StringType:68 - returning 'nico1111' as column: NUMPER1_
15:20:41,306?DEBUG StringType:68 - returning '358        ' as column: NUMLMD1_
15:20:41,306?DEBUG SessionImpl:1982 - loading [lm.met.vo.Contrat#358        ]
15:20:41,306?DEBUG SessionImpl:2079 - attempting to resolve [lm.met.vo.Contrat#358        ]
15:20:41,306?DEBUG SessionImpl:2112 - object not resolved in any cache [lm.met.vo.Contrat#358        ]
15:20:41,306?DEBUG EntityPersister:416 - Materializing entity: [lm.met.vo.Contrat#358        ]
15:20:41,306?DEBUG BatcherImpl:196 - about to open: 4 open PreparedStatements, 4 open ResultSets
15:20:41,306?DEBUG SQL:237 - select contrat0_.NUMLMD as NUMLMD2_, contrat0_.DATEFF as DATEFF2_, contrat0_.DATSIG as DATSIG2_, contrat0_.DEVISE as DEVISE2_, contrat0_.INDEXT as INDEXT2_, contrat0_.TYPCON as TYPCON2_, contrat0_.LIBCON as LIBCON2_, contrat0_.NUMLML as NUMLML2_, contrat0_.NUMPER as NUMPER2_, contrat0_.NUMGEN as NUMGEN2_, etat1_.NUMLMD as NUMLMD0_, etat1_.DATEFF as DATEFF0_, etat1_.LIBETA as LIBETA0_, etat1_.LIDCRE as LIDCRE0_, ctxadh2_.NUMPER as NUMPER__, ctxadh2_.NUMLMD as NUMLMD__, ctxadh2_.NUMPER as NUMPER1_, ctxadh2_.NUMLMD as NUMLMD1_, ctxadh2_.EFFADE as EFFADE1_, ctxadh2_.LIDCRE as LIDCRE1_, ctxadh2_.DEVISE as DEVISE1_, ctxadh2_.DATCRE as DATCRE1_ from ccd_contrat contrat0_ left outer join ccd_etat etat1_ on contrat0_.NUMLMD=etat1_.NUMLMD left outer join ccd_adherente ctxadh2_ on contrat0_.NUMLMD=ctxadh2_.NUMLMD where contrat0_.NUMLMD=?
Hibernate: select contrat0_.NUMLMD as NUMLMD2_, contrat0_.DATEFF as DATEFF2_, contrat0_.DATSIG as DATSIG2_, contrat0_.DEVISE as DEVISE2_, contrat0_.INDEXT as INDEXT2_, contrat0_.TYPCON as TYPCON2_, contrat0_.LIBCON as LIBCON2_, contrat0_.NUMLML as NUMLML2_, contrat0_.NUMPER as NUMPER2_, contrat0_.NUMGEN as NUMGEN2_, etat1_.NUMLMD as NUMLMD0_, etat1_.DATEFF as DATEFF0_, etat1_.LIBETA as LIBETA0_, etat1_.LIDCRE as LIDCRE0_, ctxadh2_.NUMPER as NUMPER__, ctxadh2_.NUMLMD as NUMLMD__, ctxadh2_.NUMPER as NUMPER1_, ctxadh2_.NUMLMD as NUMLMD1_, ctxadh2_.EFFADE as EFFADE1_, ctxadh2_.LIDCRE as LIDCRE1_, ctxadh2_.DEVISE as DEVISE1_, ctxadh2_.DATCRE as DATCRE1_ from ccd_contrat contrat0_ left outer join ccd_etat etat1_ on contrat0_.NUMLMD=etat1_.NUMLMD left outer join ccd_adherente ctxadh2_ on contrat0_.NUMLMD=ctxadh2_.NUMLMD where contrat0_.NUMLMD=?
15:20:41,321?DEBUG BatcherImpl:241 - preparing statement
15:20:41,321?DEBUG StringType:46 - binding '358        ' to parameter: 1
15:20:41,321?DEBUG Loader:197 - processing result set
15:20:41,337?DEBUG StringType:68 - returning '358        ' as column: NUMLMD0_
15:20:41,337?DEBUG StringType:68 - returning 'nico1111' as column: NUMPER1_
15:20:41,337?DEBUG StringType:68 - returning '358        ' as column: NUMLMD1_
15:20:41,337?DEBUG SessionImpl:1982 - loading [lm.met.vo.Contrat#358        ]
15:20:41,337?DEBUG SessionImpl:2079 - attempting to resolve [lm.met.vo.Contrat#358        ]
15:20:41,337?DEBUG SessionImpl:2112 - object not resolved in any cache [lm.met.vo.Contrat#358        ]
15:20:41,337?DEBUG EntityPersister:416 - Materializing entity: [lm.met.vo.Contrat#358        ]



Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 4:12 am 
Newbie

Joined: Thu Aug 26, 2004 8:50 am
Posts: 6
I'm still trying to get it work,
Does anybody successfully use a "key-many-to-one" with the outer-join option one the parent side ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 4:43 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
what happens when you copy paste the generated sql?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 5:16 am 
Newbie

Joined: Thu Aug 26, 2004 8:50 am
Posts: 6
The generated sql works ok and returns both the parent's properties and the child's properties on the same line.

Thanks for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 5:19 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
i don't really see what can the problem be.
So let's debug,
change
Code:
<class
        name="lm.met.vo.Contrat"
        table="ccd_contrat"
        dynamic-update="false"
        dynamic-insert="false"
    >


to
Code:
<class
        name="lm.met.vo.Contrat"
        table="ccd_contrat"
        dynamic-update="false"
        dynamic-insert="false"
        lazy="true"
    >


and add a default constructor to Contract class,
this will lazy load all to-one association to this class

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 5:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
It is *quite* hard to implement equals()/hashCode() correctly for a composite key with a <key-many-to-one>.

Focus on that, since that as where the problem is (as per the FAQ).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 5:26 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
sorry, i didn't know it, now it's noted

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 5:28 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
cheers man, thanks for helping :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 5:48 am 
Newbie

Joined: Thu Aug 26, 2004 8:50 am
Posts: 6
Thanks both of you.

Anthony, when i changed my mapping file to added lazy="true" as you told me to do, i suddenly saw the log i added in the hascode and equals method of my key !

Now with the lazy="true" on parent side It works ok but without that, i loop again (and it doesn't even use the hascode and equals method) ...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 5:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I really do not believe that you have a correct hashCode/equals on ContexteAdherenteKey.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 5:55 am 
Newbie

Joined: Thu Aug 26, 2004 8:50 am
Posts: 6
I agree with that .
I'll have change my ContexteAdherenteKey to add another discrimant property.

But what fooled me is that these methods are not called without the lazy="true" option so i thought there was another problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 27, 2004 6:32 am 
Newbie

Joined: Thu Aug 26, 2004 8:50 am
Posts: 6
Ok, i changed my hascode and equals methods on the key, same result (not really surprising as they're not called ;)

But it works as I expected with the lazy="true" on the parent side so I'll do it that way.

Thanks again both of you.
nicolas


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