ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nathan Maves" <nathan.ma...@gmail.com>
Subject Re: Ibatis caching Empty ResultSet
Date Sat, 09 Feb 2008 21:12:11 GMT
The real question is why are you not clearing the cache on the insert
statement?

This would solve your issue and ensure that your cache is always in a
"clean" state.  I know you claim that this "makes no sense" but it does :)
As long as you are issues more then one select between inserts which is
normally the case.


Nathan

On Feb 9, 2008 9:55 AM, Jeff Butler <jeffgbutler@gmail.com> wrote:

> This behavior makes perfect sense to me - caches are generally agnostic
> about the content of the cache.  They shouldn't behave one way for one kind
> of result and another way for others.  An empty result set represents an
> accurate representation of the DB at the time the first query is performed.
> Suppose you never did the insert...you would want to cache the empty result
> to avoid re-querying the DB wouldn't you?  This is the entire purpose of a
> cache.
>
> If you want to change this behavior, then you might be able to write your
> own cache controller to plugin to iBATIS, or perhaps you could make some
> configuration of OSCACHE that would work this way.  I'm not sure about
> that.  But the behavior you are experiencing seems like the way it *should*
> work to me.
>
> Jeff Butler
>
>
>
>
> On Feb 9, 2008 8:09 AM, Serge Sozonoff <serge@sozonoff.com> wrote:
>
> > Hi All,
> >
> > I am experiencing some strange behavior with the iBatis cache (iBatis
> > version 2.3.x)
> >
> > It seems like iBatis is caching empty ResultSets/ResultMap, below is a
> > select statement for a user which does not exist in the database.
> > Notice the last line iBatis is caching something but its not a User
> > object which is what it would be for a select with an existing user as
> > seen in the second log extract.
> >
> > Any thoughts anyone?
> >
> > This is a problem for me in the following scenario.
> >
> > select user to see if he/she exists
> > insert user because does not exist
> > .... later ... select the user which now exists
> >
> > In the above scenario the third statements returns a null object because
> > it is returning the "null" object which was cached from the first
> > statement!
> > To make this work I would have to flush the cache every time I insert
> > the new user which to me makes no sense at all.
> >
> > Thanks,
> > Serge
> >
> > Output for select of non existing user with a strange cache behavior.
> >
> > 09 Feb 2008 14:40:10,406 47078 [http-8080-2] DEBUG
> > java.sql.PreparedStatement  - {pstm-100004} Executing
> > Statement:          SELECT * FROM users         WHERE username = ?
> > 09 Feb 2008 14:40:10,406 47078 [http-8080-2] DEBUG
> > java.sql.PreparedStatement  - {pstm-100004} Parameters: [usera]
> > 09 Feb 2008 14:40:10,406 47078 [http-8080-2] DEBUG
> > java.sql.PreparedStatement  - {pstm-100004} Types: [java.lang.String]
> > 09 Feb 2008 14:40:10,406 47078 [http-8080-2] DEBUG java.sql.ResultSet  -
> > {rset-100005} ResultSet
> > 09 Feb 2008 14:40:10,406 47078 [http-8080-2] DEBUG
> > com.ibatis.sqlmap.engine.cache.CacheModel  - Cache 'User.user-cache':
> > stored object 'java.lang.Object@5b02a6'
> >
> >
> > Output for a select of an existing user
> >
> > 09 Feb 2008 15:02:49,859 245953 [http-8080-1] DEBUG
> > java.sql.PreparedStatement  - {pstm-100009} Executing
> > Statement:          SELECT * FROM users         WHERE username = ?
> > 09 Feb 2008 15:02:49,859 245953 [http-8080-1] DEBUG
> > java.sql.PreparedStatement  - {pstm-100009} Parameters: [userc]
> > 09 Feb 2008 15:02:49,859 245953 [http-8080-1] DEBUG
> > java.sql.PreparedStatement  - {pstm-100009} Types: [java.lang.String]
> > 09 Feb 2008 15:02:49,859 245953 [http-8080-1] DEBUG java.sql.ResultSet
> > - {rset-100010} ResultSet
> > 09 Feb 2008 15:02:49,859 245953 [http-8080-1] DEBUG java.sql.ResultSet
> > - {rset-100010} Header: [id, username, password_hash,
> > pwd_reminder_email, active]
> > 09 Feb 2008 15:02:49,859 245953 [http-8080-1] DEBUG java.sql.ResultSet
> > - {rset-100010} Result: [7, userc, w1vwW2KgIeg=, email@email.com, true]
> > 09 Feb 2008 15:02:49,859 245953 [http-8080-1] DEBUG
> > com.ibatis.sqlmap.engine.cache.CacheModel  - Cache 'User.user-cache':
> > stored object 'com.echovox.sso.domain.User@14492fb'
> >
>
>

Mime
View raw message