Re: [Objectbridge-developers] A few problems
Brought to you by:
thma
From: Kief M. <ki...@bi...> - 2001-07-30 10:21:30
|
Kief Morris typed the following on 11:27 AM 7/30/2001 +0300 >2) ObjectCache doesn't appear to retrieve referenced objects. When I > store and then retrieve an object which references a collection, the > retrieved object doesn't have the collection items. If I insert: > > ojb.broker.accesslayer.ObjectCache.getInstance().clear(); > > - between the store and the find, the retrieved object *does* have > the collection. I don't totally understand this - presumably the cache > should return the same object, including its references, but a comparison > of the two objects without the above call shows one has the collection, > the other's collection is empty. Aha! The cache wasn't returning the same object, because objects were only being added to the cache (as far as I can tell) when they were retrieved from the DB, not when they were saved. So consider the following steps: 1) create new object 2) store it 3) retrieve a copy of the object 4) compare the object references The comparison failed, because the objects were different instances. So I've attached a small patch which causes the PersistentManager to add items to the cache when they are stored. Maybe this is redundant for updates, it could be moved inside the conditional so it only happens on inserts. I didn't dig into the reason why the loaded copy of the original object didn't load its referenced collection - as I mentioned in the previous message, clearing the cache and then loading the copy did in fact load the collection. I'm guessing there is a check somewhere which caught the fact that the collection was already loaded in memory, so didn't bother to reload it. At any rate it seems to work fine now. Regards, Kief |