It is supposed to be like that.
If you want to get an existing instance which is already in memory instead
of creating a new one each time you need to create some sort of caching
mechanism (easiest - just put them in a Hashtable).  The right place to do
this (i think) is row2object method of the corresponding Peer. override it
to the the following:

1. call row2object of the superclass (which converts the row to the object -
always a new instance)
2. check if an object with same PK is already in the cache:
if it is there - discard the new object (let it be gc()'ed) and return the
one from the cache;
if it is not there - put it into the cache and return it.


be careful, though, as in this case you may not always get the freshest
object possible....

fedor.


> -----Original Message-----
> From: Xavier [mailto:[EMAIL PROTECTED]]
> Sent: Friday, July 13, 2001 12:00 AM
> To: Turbine-User
> Subject: Different instance of the same object
> 
> 
> Hi,
> 
> I have some problem with multiple instant of one object in 
> the simple case
> --------------------------------------------------------------
> --------------
> -
> ....
> Criteria myC = new Criteria();
> myC.add(ParentPeer.ID,"1");
> Vector aResultList = ParentPeer.doSelect(myC); // myParent is 
> load from db
> 
> myParent = (Parent)aResultList.firstElement();
> 
> myChild = (Child)myParent.getChilds().get(1); // myChild is 
> load from db
> 
> myParent2 = myChild.getParent(); // myParent is load again from db
> ----------------------------------------------------------------
> 
> myParent and myParent2 are different instance!
> It's possible to avoid that? it's forecast?
> 
> Xa
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to