Hi Dave,

Dave Hodson wrote:
> I have a basic question about object caching. Using the sample code
> in Tutorial 1, I understand how to do things like QueryByIdentity to
> pull objects from a database (for example, provide a product ID to
> retrieve a Product object). I also understand (and have seen via the
> spy) that objects retrieved this way are cached in RAM after the
> initial lookup.
>

correct !

> However, it seems when I use QueryByCriteria, I get the results, not
> from the cache, but from the database. Based on what I have read on
> the OJB website, I'm thinking that this happens specifically because
> the criteria I'm using is not one of the db primary keys (e.g. Using
> Tutorial 1 as an example, if I query using the NAME column, OJB goes
> to the database to retrieve the value, but does not cache the outcome
> so any subsequent calls with the same NAME also hit the database, not
> the cache)

Things are working a bit different.
If you are performing a QueryByCriteria a SQL statement reflecting the criteria is executed.
OJB than iterates over the corresponding resultset to materialize objects from each row of the resultset.
Before an object is actually materialized OJB takes the primary key information from the current resultset row and builds an Identity from it. OJB then looks up the cache if there is already stored an Object for this Identity in the cache.
If so the cached object is used. If not the object is read in from the resultset.

>
> If my thoughts are correct (let me know if they are not!), is there a
> way to cache an object retrieved from the database with a
> QueryByCriteria call, when the critieria consists of a field or
> fields that are not one of the primary keys?
>

As mentioned above: this is already implemented. But OJB still has to execute a full SQL statement to get the raw data.

cheers,
Thomas

> Dave --- Dave Hodson MessageCast, inc. Email: [EMAIL PROTECTED]
> www.messagecast.net
>
>

Hi



--
To unsubscribe, e-mail: <mailto:ojb-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:ojb-user-help@;jakarta.apache.org>

Reply via email to