Re: Problem/misunderstanding with ObjectCache, multiple databases and ObjectModification, 1.0.4
Armin Waibel <[email protected]>
| Newsgroups | gmane.comp.jakarta.ojb.user |
|---|---|
| Message-ID | <[email protected]> |
Hi Bernd,
Längerich wrote:
> Hi,
>
> I have some problems understanding (and using) the concept of the cache when using multiple databases and determining the object modification level at the store method.
>
> Assume we have two databases A and B with one being the default and one being the backup database. Both connections are configured using the cache:
> <object-cache class="org.apache.ojb.broker.cache.ObjectCacheDefaultImpl">
> <attribute attribute-name="timeout" attribute-value="-1"/>
> </object-cache>
>
> Given the following code sequence with empty databases, I have some problems:
>
> AnObject someObject = new AnObject();
> [...]
> PersistenceBroker defaultBroker = PersistenceBrokerFactory.defaultPersistenceBroker();
> defaultbroker.store(someObject); // resulting in an INSERT to the default DB
> [...]
> defaultBroker.store(someObject); // resulting in an UPDATE to the default DB
>
> PersistenceBroker backupBroker = PersistenceBrokerFactory.createPersistenceBroker(new PBKey("backup"));
> backupBroker.store(someObject); // resulting in an UPDATE to the backup DB, which fails as there is no such row in the DB
>
>
> As far as I understand the code from PersistanceBrokerImpl, it should query the cache and/or the DB:
> /*
> if PK values are set, lookup cache or db to see whether object
> needs insert or update
> */
> if (!insert)
> {
> insert = objectCache.lookup(oid) == null
> && !serviceBrokerHelper().doesExist(cld, oid, obj);
> }
> store(obj, oid, cld, insert);
>
> The insert should be false, as the PK fields are not null, and the objectCache for the backupBroker should give null.
> I traced with P6Spy, but I can't detect a SELECT to determine the existence of the row, so I assume the objectCache.lookup(oid) returns true.
>
> Any hints?
You are right, OJB find the object in the cache (because you operate
with the same objects on different DB's using a shared cache) and
indicate to update the object instead of insert.
Do you really need a shared cache on your "backup" broker? I would
recommend to use a "per broker cache" (for backup-broker)
http://db.apache.org/ojb/docu/guides/objectcache.html#ObjectCachePerBrokerImpl
Then OJB will not find the object in the cache of backup-broker and
perform a DB select.
regards,
Armin
>
> Bernd
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>