Hi,

> -----Urspr�ngliche Nachricht-----
> Von: David Corbin [mailto:[EMAIL PROTECTED]]
> Gesendet: Mittwoch, 11. September 2002 12:17
> An: OJB Users List
> Betreff: Re: AW: Caching question
> 
> 
> Can you point out where yor previous answer is, quote it, or 
> explain to 
> me why?  (I looked but couldn't find it)  Thanks.

http://archives.apache.org/eyebrowse/ReadMsg?[EMAIL PROTECTED]
e.org&msgId=465528

> 
> Part of my "quest for the holy grail", is that no logical 
> object should 
> ever exist as two different Java instances (at the same 
> time).  I have, 
> at least for the moment, the luxury of living in a single JVM.

In general the OJB cache maintans uniqueness of objects:
That is two lookups with equal Identity objects will serve the same
instance:

Object[] pkValues = {17};

// two Identities pointing to same Instance !
Identity oid1 = new Identity(Product.class, pkValues);
Identity oid2 = new Identity(Product.class, pkValues);

Product obj1 = broker.getObjectByIdentity(oid1);
Product obj2 = broker.getObjectByIdentity(oid2);

assertEquals(obj1,obj2);
assertEquals((obj1 == obj2), true);

But (as mentioned in my message quoted above) several things (like clearing
the cache) can happen that may break te second assertion!

SO it's generally not safe to rely on this behaviour.

cheers,
Thomas

> David
> Mahler Thomas wrote:
> 
> >Hi again,
> >
> >As mentioned in my previous answer, there are situation 
> where it is not safe
> >to rely on instance *identity* after a lookup.
> >
> >you should build you apps in a way that they only rely on 
> *equivalence*.
> >
> >see a sample testcase:
> >http://jakarta.apache.org/ojb/xref/org/apache/ojb/broker/Pers
> istenceBrokerTe
> >st.html#523
> >
> >cheers,
> >Thomas
> >
> >  
> >
> >>elhar, Wallace J. wrote:
> >>
> >>    
> >>
> >>>Frank,
> >>>
> >>>As stated in another email, the cache uses weak references.  
> >>>      
> >>>
> >>This means
> >>    
> >>
> >>>that if you create the object, release your reference (At 
> >>>      
> >>>
> >>this point is
> >>    
> >>
> >>>it fair game for garbage collection).  \Then subsequently load the
> >>>object, OJB will check the cache and if not present will 
> >>>      
> >>>
> >>load from the
> >>    
> >>
> >>>DB and create a new object with the same OID (and obviously data
> >>>values).  I am not an expert, but I believe it's always a 
> >>>      
> >>>
> >>good idea to
> >>    
> >>
> >>>overload .equals on your business objects anyways for 
> >>>      
> >>>
> >>comparison in your
> >>    
> >>
> >>>applications.
> >>> 
> >>>
> >>>      
> >>>
> >>I'm talking about an IMMEDATE load write after creating, and while 
> >>holding the original object still.  This was something I 
> >>noticed while 
> >>debugging a problem in some test code.
> >>
> >>
> >>
> >>--
> >>To unsubscribe, e-mail:   
> >><mailto:[EMAIL PROTECTED]>
> >>For additional commands, e-mail: 
> >><mailto:[EMAIL PROTECTED]>
> >>
> >>    
> >>
> >
> >--
> >To unsubscribe, e-mail:   
<mailto:[EMAIL PROTECTED]>
>For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>  
>




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

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

Reply via email to