-->
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.  [ 6 posts ] 
Author Message
 Post subject: Endless Loop when calling toString for bidirectional associa
PostPosted: Sat Apr 29, 2006 3:55 am 
Beginner
Beginner

Joined: Mon Jan 24, 2005 11:56 am
Posts: 24
Hi,

version: hibernatetools-3.1.0.beta5

I am using the generated toString method, but it seems that generated code falls in a loop for bidirectional associations:
as a sample imagine account and activity entities
Code:
<class name="Account">
        <id name="id" column="Account_Id" type="long">
            <generator class="increment"/>
        </id>
        <set name="activity" inverse="true" >
            <key column="Account_Id"/>
            <one-to-many class="Activity"/>
        </set>
    </class>
**********************
<class name="Activity">
    <id name="id" column="Activity_Id" type="long">
         <generator class="increment"/>
      </id>
      <many-to-one name="account" unique="false"
                 not-null="false" class="Account"
            column="Account_Id" foreign-key="FK_Activity_Account"/>
</class>


Then the generated toStrings are:
Code:
Account
toString()
  {
  (1)buffer.append("activity").append("='").append(getActivity()).append("'    ");
  }

********************
Acitivity{
tostring()
{
   (2)buffer.append("account").append("='").append(getAccount()).append("' ");
}



Line (1) and (2) are the lines which keep calling each other when I try to write Account Entity.

Same goes with hascode() method.

Please help

Regards,
Alireza Fattahi


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 29, 2006 9:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the tools does not generate any toString unless you specify meta attributes with use-in-tostring.

so the tools did should generate that tostring based on what you showed me. (and if you for some reason has use-in-tostring specified at a higher level and thus have it inherited then you should not do that if you want to bump into recursiveness.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 29, 2006 10:33 am 
Beginner
Beginner

Joined: Mon Jan 24, 2005 11:56 am
Posts: 24
Dear Max,

Yes, I have put to-string meta at the class level (just above the class tag)

But I did not get your idea! Should I put use-in-tostring for each property of the class individually, so if the class has 10 properties I should copy and paste in 10 times!
Is there any way that I can manage it.

Regards,
Alireza Fattahi


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 29, 2006 10:44 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
well, how do you want me to decide/figure out which of your properties should not be included ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 30, 2006 3:13 am 
Beginner
Beginner

Joined: Mon Jan 24, 2005 11:56 am
Posts: 24
Hi,

Can we put to-string for a class and define which properties must NOT be considered in generated to-string method?

Regards,
Alireza Fattahi


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 30, 2006 4:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
no, not with the current functionallity.

_________________
Max
Don't forget to rate


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