You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Günther Wieser <gw...@creative-it.com> on 2005/04/04 14:13:43 UTC

problem with ojb when overwriting the toString() method

hi,

this weekend ojb brought me a lot of "fun". i'd been searching for a problem
for over half a day until i found out that ojb didn't like the way i
overwrote the toString() method ob the objects that i wanted to be
persisted.

finally i found some debug output like "BAD toString() implementation of
class xxxxx", but couldn't find any further details.

anyone an idea how i can implement an ojb compatible toString() method
output, and what ojb does with the result of the toString() method?

kr,
guenther


RE: problem with ojb when overwriting the toString() method

Posted by Günther Wieser <gw...@creative-it.com>.
> ... so OJB found a bug in your code ;-)

i'm thinking about replacing my unit test with ojb, it's the perfect tool to
find bugs ;-)

-----Original Message-----
From: Armin Waibel [mailto:arminw@apache.org] 
Sent: Monday, April 04, 2005 5:54 PM
To: OJB Users List
Subject: Re: problem with ojb when overwriting the toString() method

... so OJB found a bug in your code ;-)

Armin

Günther Wieser wrote:
> hi,
> 
> finally i found the problem. i started to make my tests more complex, 
> and then i found the big error (and the reason why i get a stack 
> overflow): i have objects that are liked bidirectionally with each 
> other. i call
> toString() on one of these objects, it dumps all private fields 
> INCLUDING the referenced object. as the referenced object's toString() 
> method is called, and as it references itself the first object again, 
> a circular reference is being established, a lot of toString() methods 
> on the same objects are being called again and again, and the stack
overflow happens.
> didn't see that happening in my code before as i called toString() on 
> my objects BEFORE i linked them bidirectionally.....
> 
> kr,
> guenther
> 
> -----Original Message-----
> From: Thomas Franke [mailto:franke@softenergy.de]
> Sent: Monday, April 04, 2005 3:12 PM
> To: OJB Users List
> Subject: Re: problem with ojb when overwriting the toString() method
> 
> Günther Wieser wrote:
> 
> 
>>hmm, haven't seen any error so far when using the toString() method of 
>>objects of this class so far.
>>what the toString() method does is to get all private fields of the 
>>object by introspection and fill a string buffer with the name of the 
>>field and the value.
> 
> Could I take a look on your source code?
> 
> regards
> 
> Thomas
> --
> Mit freundlichen Grüßen
> 
> Thomas Franke
> 
> Geschäftsführer
> Leiter Entwicklung
> ------------------------------
> the energy for a better world
> ------------------------------
> softEnergy GmbH
> Platz der Freundschaft 1
> 18059 Rostock
> ------------------------------
> fon: +49 381 40 587 535
> fax: +49 381 40 587 555
> mobil: +49 1715222015
> 
> http://www.softenergy.de
> mail: info@softenergy.de
> ------------------------------
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: problem with ojb when overwriting the toString() method

Posted by Armin Waibel <ar...@apache.org>.
... so OJB found a bug in your code ;-)

Armin

Günther Wieser wrote:
> hi,
> 
> finally i found the problem. i started to make my tests more complex, and
> then i found the big error (and the reason why i get a stack overflow): i
> have objects that are liked bidirectionally with each other. i call
> toString() on one of these objects, it dumps all private fields INCLUDING
> the referenced object. as the referenced object's toString() method is
> called, and as it references itself the first object again, a circular
> reference is being established, a lot of toString() methods on the same
> objects are being called again and again, and the stack overflow happens.
> didn't see that happening in my code before as i called toString() on my
> objects BEFORE i linked them bidirectionally.....
> 
> kr,
> guenther
> 
> -----Original Message-----
> From: Thomas Franke [mailto:franke@softenergy.de] 
> Sent: Monday, April 04, 2005 3:12 PM
> To: OJB Users List
> Subject: Re: problem with ojb when overwriting the toString() method
> 
> Günther Wieser wrote:
> 
> 
>>hmm, haven't seen any error so far when using the toString() method of 
>>objects of this class so far.
>>what the toString() method does is to get all private fields of the 
>>object by introspection and fill a string buffer with the name of the 
>>field and the value.
> 
> Could I take a look on your source code?
> 
> regards
> 
> Thomas
> --
> Mit freundlichen Grüßen
> 
> Thomas Franke
> 
> Geschäftsführer
> Leiter Entwicklung
> ------------------------------
> the energy for a better world
> ------------------------------
> softEnergy GmbH
> Platz der Freundschaft 1
> 18059 Rostock
> ------------------------------
> fon: +49 381 40 587 535
> fax: +49 381 40 587 555
> mobil: +49 1715222015
> 
> http://www.softenergy.de
> mail: info@softenergy.de
> ------------------------------
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


RE: problem with ojb when overwriting the toString() method

Posted by Günther Wieser <gw...@creative-it.com>.
hi,

finally i found the problem. i started to make my tests more complex, and
then i found the big error (and the reason why i get a stack overflow): i
have objects that are liked bidirectionally with each other. i call
toString() on one of these objects, it dumps all private fields INCLUDING
the referenced object. as the referenced object's toString() method is
called, and as it references itself the first object again, a circular
reference is being established, a lot of toString() methods on the same
objects are being called again and again, and the stack overflow happens.
didn't see that happening in my code before as i called toString() on my
objects BEFORE i linked them bidirectionally.....

kr,
guenther

-----Original Message-----
From: Thomas Franke [mailto:franke@softenergy.de] 
Sent: Monday, April 04, 2005 3:12 PM
To: OJB Users List
Subject: Re: problem with ojb when overwriting the toString() method

Günther Wieser wrote:

> hmm, haven't seen any error so far when using the toString() method of 
> objects of this class so far.
> what the toString() method does is to get all private fields of the 
> object by introspection and fill a string buffer with the name of the 
> field and the value.
Could I take a look on your source code?

regards

Thomas
--
Mit freundlichen Grüßen

Thomas Franke

Geschäftsführer
Leiter Entwicklung
------------------------------
the energy for a better world
------------------------------
softEnergy GmbH
Platz der Freundschaft 1
18059 Rostock
------------------------------
fon: +49 381 40 587 535
fax: +49 381 40 587 555
mobil: +49 1715222015

http://www.softenergy.de
mail: info@softenergy.de
------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: problem with ojb when overwriting the toString() method

Posted by Thomas Franke <fr...@softenergy.de>.
Günther Wieser wrote:

> hmm, haven't seen any error so far when using the toString() method of
> objects of this class so far.
> what the toString() method does is to get all private fields of the object
> by introspection and fill a string buffer with the name of the field and the
> value.
Could I take a look on your source code?

regards

Thomas
-- 
Mit freundlichen Grüßen

Thomas Franke

Geschäftsführer
Leiter Entwicklung
------------------------------
the energy for a better world
------------------------------
softEnergy GmbH
Platz der Freundschaft 1
18059 Rostock
------------------------------
fon: +49 381 40 587 535
fax: +49 381 40 587 555
mobil: +49 1715222015

http://www.softenergy.de
mail: info@softenergy.de
------------------------------

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: problem with ojb when overwriting the toString() method

Posted by Armin Waibel <ar...@apache.org>.
Günther Wieser wrote:
> hi,
> 
> hmm, haven't seen any error so far when using the toString() method of
> objects of this class so far.
> what the toString() method does is to get all private fields of the object
> by introspection and fill a string buffer with the name of the field and the
> value.
> 
> i will look deeper into this later today, but, as mentioned, haven't seen
> any problems so far with this method outside ojb. so if you have any other
> idea what could cause this problem, i would very much appreciate that.
>

Sorry, this is the only idea I have. Have a look in one of the Logger 
implementations classes, e.g. PoorMansLoggerImpl. Here you can see how 
it works.

regards,
Armin


> kr,
> guenther
> 
> --
> Günther Wieser
> 
> creative-it
> Guglgasse 6/1/11/1
> A-1110 Wien
> Austria
> http://www.creative-it.com
> 
> 
> -----Original Message-----
> From: Armin Waibel [mailto:arminw@apache.org] 
> Sent: Monday, April 04, 2005 2:27 PM
> To: OJB Users List
> Subject: Re: problem with ojb when overwriting the toString() method
> 
> Hi Günther,
> 
> Günther Wieser wrote:
> 
>>hi,
>>
>>this weekend ojb brought me a lot of "fun". i'd been searching for a 
>>problem for over half a day until i found out that ojb didn't like the 
>>way i overwrote the toString() method ob the objects that i wanted to 
>>be persisted.
>>
>>finally i found some debug output like "BAD toString() implementation 
>>of class xxxxx", but couldn't find any further details.
>>
>>anyone an idea how i can implement an ojb compatible toString() method 
>>output, and what ojb does with the result of the toString() method?
>>
> 
> 
> The "BAD toString()..." comment was cause by an exception thrown by the
> #toString() method of your persistent objet.
> When OJB is logging some times the persistent object itself was logged too.
> In this case OJB checks if the #toString method of the object is valid to
> use. If not (#toString throws an exception) the "BAD toString..." entry is
> shown.
> 
> Could it be the case that the #toString method of your persistent object is
> cause an exception?
> 
> regards,
> Armin
> 
> 
> 
>>kr,
>>guenther
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


RE: problem with ojb when overwriting the toString() method

Posted by Günther Wieser <gw...@creative-it.com>.
hi,

hmm, haven't seen any error so far when using the toString() method of
objects of this class so far.
what the toString() method does is to get all private fields of the object
by introspection and fill a string buffer with the name of the field and the
value.

i will look deeper into this later today, but, as mentioned, haven't seen
any problems so far with this method outside ojb. so if you have any other
idea what could cause this problem, i would very much appreciate that.

kr,
guenther

--
Günther Wieser

creative-it
Guglgasse 6/1/11/1
A-1110 Wien
Austria
http://www.creative-it.com


-----Original Message-----
From: Armin Waibel [mailto:arminw@apache.org] 
Sent: Monday, April 04, 2005 2:27 PM
To: OJB Users List
Subject: Re: problem with ojb when overwriting the toString() method

Hi Günther,

Günther Wieser wrote:
> hi,
> 
> this weekend ojb brought me a lot of "fun". i'd been searching for a 
> problem for over half a day until i found out that ojb didn't like the 
> way i overwrote the toString() method ob the objects that i wanted to 
> be persisted.
> 
> finally i found some debug output like "BAD toString() implementation 
> of class xxxxx", but couldn't find any further details.
> 
> anyone an idea how i can implement an ojb compatible toString() method 
> output, and what ojb does with the result of the toString() method?
> 

The "BAD toString()..." comment was cause by an exception thrown by the
#toString() method of your persistent objet.
When OJB is logging some times the persistent object itself was logged too.
In this case OJB checks if the #toString method of the object is valid to
use. If not (#toString throws an exception) the "BAD toString..." entry is
shown.

Could it be the case that the #toString method of your persistent object is
cause an exception?

regards,
Armin


> kr,
> guenther
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org


Re: problem with ojb when overwriting the toString() method

Posted by Armin Waibel <ar...@apache.org>.
Hi Günther,

Günther Wieser wrote:
> hi,
> 
> this weekend ojb brought me a lot of "fun". i'd been searching for a problem
> for over half a day until i found out that ojb didn't like the way i
> overwrote the toString() method ob the objects that i wanted to be
> persisted.
> 
> finally i found some debug output like "BAD toString() implementation of
> class xxxxx", but couldn't find any further details.
> 
> anyone an idea how i can implement an ojb compatible toString() method
> output, and what ojb does with the result of the toString() method?
> 

The "BAD toString()..." comment was cause by an exception thrown by the 
#toString() method of your persistent objet.
When OJB is logging some times the persistent object itself was logged 
too. In this case OJB checks if the #toString method of the object is 
valid to use. If not (#toString throws an exception) the "BAD 
toString..." entry is shown.

Could it be the case that the #toString method of your persistent object 
is cause an exception?

regards,
Armin


> kr,
> guenther
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org