You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Christopher DeGuise <ch...@be-pragmatic.com> on 2007/08/08 19:32:43 UTC

PATCH: Re: Possible bug in CacheModel with QueryForObject

Hi All,

I just ran in to this issue and I could not find any responses to the
original poster. I created a fix that that solves the problem to the best of
my testing ability and have included the patch here. The root problem is
that the second time the query is executed the result is retrieved from the
cache. The cache assumes that a cast to the desired type would be
successful.

Should I submit this to the multi language developer list or is this fine? I
know at one time the maintainers followed this list regularly.

Chris

On 6/14/07, Kenneth Olsen <ke...@gatetrade.net> wrote:
>
>  I may have found a bug in iBatis 1.6 (latest) with caching.
>
>
>
> Got a map with this:
>
>
>
> <cacheModels>
>
> <cacheModel id="cacheUser" implementation="LRU">
>
> <flushInterval hours="24"/>
>
> <flushOnExecute statement="stiInsertUser"/>
>
> </cacheModel>
>
> </cacheModels>
>
>
>
> And a SELECT statement with this:
>
>
>
> <select id="stsGetOnEmail" parameterClass="System.String" resultMap="
> resUser" cacheModel="cacheUser">
>
> SELECT * FROM users WHERE Email = #value#
>
> </select>
>
>
>
>
>
> In code I use:
>
>
>
> User _user = i.QueryForObject<User>("stsGetOnEmail", email);
>
>
>
> When doing this, the error strikes:
>
> - I pass "1" as parameter in email, which will return NULL from db
>
> - I pass "1" again as parameter in email, which and the error pops up with:
> Unable to cast object of type 'System.Object' to type 'Domain.User'.
>
>
>
> I suspect, it caches something the first time? But how if the returned
> object is NULL?
>
>
>
> Log:
>
>
>
> 2007-06-13 22:36:48,091 Adding file [SqlMap.config] to list of watched
> files.
> 2007-06-13 22:36:48,404 Statement Id: [stsGet] Prepared SQL:
> [SELECT         UserID, Firstname, Lastname, City, Description, Email,
> AES_DECRYPT(Password, Salt) AS Password, Salt, Company, Question, Answer,
> LoginAttempts, LastLoginDate, Status, CreatedDate, UpdatedDate       FROM
> users WHERE UserID =  ?param0]
> 2007-06-13 22:36:48,419 Statement Id: [stsGetIDAndEmail] Prepared SQL:
> [SELECT         UserID, Firstname, Lastname, City, Description, Email,
> AES_DECRYPT(Password, Salt) AS Password, Salt, Company, Question, Answer,
> LoginAttempts, LastLoginDate, Status, CreatedDate, UpdatedDate       FROM
> users WHERE Email =  ?param0               AND UserID =  ?param1]
> 2007-06-13 22:36:48,419 Statement Id: [stsGetOnEmail] Prepared SQL:
> [SELECT         UserID, Firstname, Lastname, City, Description, Email,
> AES_DECRYPT(Password, Salt) AS Password, Salt, Company, Question, Answer,
> LoginAttempts, LastLoginDate, Status, CreatedDate, UpdatedDate       FROM
> users WHERE Email =  ?param0]
> 2007-06-13 22:36:48,419 Statement Id: [stsGetPicture] Prepared SQL:
> [SELECT Picture, PictureContentType, PictureFilename FROM users WHERE
> UserID =  ?param0]
> 2007-06-13 22:36:48,435 Statement Id: [stiInsertUser] Prepared SQL:
> [INSERT INTO users (Firstname, Lastname, City, Description, Email,
> Password, Salt, Company, Question, Answer, LastLoginDate, Status,
> PictureContentType, PictureFilename, Picture, CreatedDate, UpdatedDate)
> VALUES ( ?param0 , ?param1 , ?param2 , ?param3 , ?param4 ,AES_ENCRYPT(
> ?param5 ,  ?param6 ), ?param6 , ?param7 , ?param8 , ?param9 , ?param10 ,
> ?param11 , ?param12 , ?param13 , ?param14 , ?param15 , ?param16 )]
> 2007-06-13 22:36:48,435 Statement Id: [stiInsertUser.SelectKey] Prepared
> SQL: [SELECT LAST_INSERT_ID() AS value]
> 2007-06-13 22:36:48,435 Statement Id: [stuUpdateLoginAttempts] Prepared
> SQL: [UPDATE users SET LoginAttempts =  ?param0 , Status =  ?param1 ,
> UpdatedDate =  ?param2  WHERE UserID =  ?param3]
> 2007-06-13 22:36:48,435 Statement Id: [stuUpdateLastLoginDate] Prepared
> SQL: [UPDATE users SET LastLoginDate =  ?param0  WHERE UserID =  ?param1]
> 2007-06-13 22:36:48,435 Statement Id: [stuActivateUser] Prepared SQL:
> [UPDATE users SET Status =  ?param0 , UpdatedDate =  ?param1  WHERE UserID=  ?param2  AND Email =  ?param3  AND Status = 2]
> 2007-06-13 22:36:48,451 Registering trigger statement [stiInsertUser] to
> cache model [User.cacheUser]
> 2007-06-13 22:36:48,498 Statement Id: [stsGetOnEmail] PreparedStatement :
> [SELECT         UserID, Firstname, Lastname, City, Description, Email,
> AES_DECRYPT(Password, Salt) AS Password, Salt, Company, Question, Answer,
> LoginAttempts, LastLoginDate, Status, CreatedDate, UpdatedDate       FROM
> users WHERE Email =  ?param0]
> 2007-06-13 22:36:48,513 Statement Id: [stsGetOnEmail] Parameters: [?param0
> =[value,1]]
> 2007-06-13 22:36:48,513 Statement Id: [stsGetOnEmail] Types: [?param0=[String,
> System.String]]
> 2007-06-13 22:36:48,529 Cache miss using key '595483856|-9223372036473027192'
>
> 2007-06-13 22:36:48,732 Open Connection "15361084" to "MySQL, MySQLprovider
> 5.0.6.0".
> 2007-06-13 22:36:48,748 Cache object 'System.Object' using key
> '595483856|-9223372036473027192'
> 2007-06-13 22:36:48,763 Close Connection "15361084" to "MySQL, MySQLprovider
> 5.0.6.0".
> 2007-06-13 22:36:48,763 Statement Id: [stsGetOnEmail] PreparedStatement :
> [SELECT         UserID, Firstname, Lastname, City, Description, Email,
> AES_DECRYPT(Password, Salt) AS Password, Salt, Company, Question, Answer,
> LoginAttempts, LastLoginDate, Status, CreatedDate, UpdatedDate       FROM
> users WHERE Email =  ?param0]
> 2007-06-13 22:36:48,763 Statement Id: [stsGetOnEmail] Parameters: [?param0
> =[value,1]]
> 2007-06-13 22:36:48,763 Statement Id: [stsGetOnEmail] Types: [?param0=[String,
> System.String]]
> 2007-06-13 22:36:48,763 Retrieved cached object 'System.Object' using key
> '595483856|-9223372036473027192'
> 2007-06-13 22:36:50,591 Statement Id: [stsGetOnEmail] PreparedStatement :
> [SELECT         UserID, Firstname, Lastname, City, Description, Email,
> AES_DECRYPT(Password, Salt) AS Password, Salt, Company, Question, Answer,
> LoginAttempts, LastLoginDate, Status, CreatedDate, UpdatedDate       FROM
> users WHERE Email =  ?param0]
> 2007-06-13 22:36:50,591 Statement Id: [stsGetOnEmail] Parameters: [?param0
> =[value,1]]
> 2007-06-13 22:36:50,591 Statement Id: [stsGetOnEmail] Types: [?param0=[String,
> System.String]]
> 2007-06-13 22:36:50,591 Retrieved cached object 'System.Object' using key
> '595483856|-9223372036473027192'
>
>
>
>
>
> Mvh Kenneth Olsen
>
>
>



-- 
Christopher DeGuise
Pragmatic Technologies, Inc.
802.881.8287

Re: PATCH: Re: Possible bug in CacheModel with QueryForObject

Posted by Gilles Bayon <ib...@gmail.com>.
Thanks for the patch.
The next time it's better to open a JIRA ticket.
Fix in SVN

-- 
Cheers,
Gilles

<a href="http://www.amazon.com/gp/registry/6JCP7AORB0LE">Wish List</a>

PATCH: Re: Possible bug in CacheModel with QueryForObject

Posted by Christopher DeGuise <ch...@be-pragmatic.com>.
Hi All,

I had sent this to the .NET iBatis users list but for completeness I thought
would send it out on the developer list where a patch should probably have
been sent to in the first place. I am currently maintaining my own version
of iBatis so I am eager to have this patch reviewed and committed.
----
I just ran in to this issue and I could not find any responses to the
original poster. I created a fix that that solves the problem to the best of
my testing ability and have included the patch here. The root problem is
that the second time the query is executed the result is retrieved from the
cache. The cache assumes that a cast to the desired type would be
successful.

Thanks,
Christopher DeGuise
Pragmatic Technologies, Inc.

On 6/14/07, Kenneth Olsen <ke...@gatetrade.net> wrote:
>
>  I may have found a bug in iBatis 1.6 (latest) with caching.
>
>
>
> Got a map with this:
>
>
>
> < cacheModels>
>
> < cacheModel id= " cacheUser" implementation =" LRU" >
>
> < flushInterval hours= "24 "/>
>
> < flushOnExecute statement= "stiInsertUser "/>
>
> </ cacheModel>
>
> </ cacheModels>
>
>
>
> And a SELECT statement with this:
>
>
>
> < select id= "stsGetOnEmail " parameterClass= "System.String " resultMap="
> resUser " cacheModel= " cacheUser" >
>
> SELECT  * FROM users WHERE Email = #value#
>
> </ select>
>
>
>
>
>
> In code I use:
>
>
>
> User _user = i.QueryForObject< User>( "stsGetOnEmail", email);
>
>
>
> When doing this, the error strikes:
>
> - I pass "1" as parameter in email, which will return NULL from db
>
> - I pass "1" again as parameter in email, which and the error pops up with:
> Unable to cast object of type 'System.Object' to type 'Domain.User'.
>
>
>
> I suspect, it caches something the first time? But how if the returned
> object is NULL?
>
>
>
> Log:
>
>
>
> 2007-06-13 22:36 :48,091 Adding file [SqlMap.config] to list of watched
> files.
> 2007-06-13 22:36:48,404 Statement Id: [stsGet] Prepared SQL:
> [SELECT         UserID, Firstname, Lastname, City, Description, Email,
> AES_DECRYPT(Password, Salt) AS Password, Salt, Company, Question, Answer,
> LoginAttempts, LastLoginDate, Status, CreatedDate, UpdatedDate       FROM
> users WHERE UserID =  ?param0]
> 2007-06-13 22:36:48,419 Statement Id: [stsGetIDAndEmail] Prepared SQL:
> [SELECT         UserID, Firstname, Lastname, City, Description, Email,
> AES_DECRYPT(Password, Salt) AS Password, Salt, Company, Question, Answer,
> LoginAttempts, LastLoginDate, Status, CreatedDate, UpdatedDate       FROM
> users WHERE Email =  ?param0               AND UserID =  ?param1]
> 2007-06-13 22:36:48,419 Statement Id: [stsGetOnEmail] Prepared SQL:
> [SELECT         UserID, Firstname, Lastname, City, Description, Email,
> AES_DECRYPT(Password, Salt) AS Password, Salt, Company, Question, Answer,
> LoginAttempts, LastLoginDate, Status, CreatedDate, UpdatedDate       FROM
> users WHERE Email =  ?param0]
> 2007-06-13 22:36 :48,419 Statement Id: [stsGetPicture] Prepared SQL:
> [SELECT Picture, PictureContentType, PictureFilename FROM users WHERE
> UserID =  ?param0]
> 2007-06-13 22:36:48,435 Statement Id: [stiInsertUser] Prepared SQL:
> [INSERT INTO users (Firstname, Lastname, City, Description, Email,
> Password, Salt, Company, Question, Answer, LastLoginDate, Status,
> PictureContentType, PictureFilename, Picture, CreatedDate, UpdatedDate)
> VALUES ( ?param0 , ?param1 , ?param2 , ?param3 , ?param4 ,AES_ENCRYPT(
> ?param5 ,  ?param6 ), ?param6 , ?param7 , ?param8 , ?param9 , ?param10 ,
> ?param11 , ?param12 , ?param13 , ?param14 , ?param15 , ?param16 )]
> 2007-06-13 22:36 :48,435 Statement Id: [stiInsertUser.SelectKey] Prepared
> SQL: [SELECT LAST_INSERT_ID() AS value]
> 2007-06-13 22:36 :48,435 Statement Id: [stuUpdateLoginAttempts] Prepared
> SQL: [UPDATE users SET LoginAttempts =  ?param0 , Status =  ?param1 ,
> UpdatedDate =  ?param2  WHERE UserID =  ?param3]
> 2007-06-13 22:36 :48,435 Statement Id: [stuUpdateLastLoginDate] Prepared
> SQL: [UPDATE users SET LastLoginDate =  ?param0  WHERE UserID =  ?param1]
> 2007-06-13 22:36 :48,435 Statement Id: [stuActivateUser] Prepared SQL:
> [UPDATE users SET Status =  ?param0 , UpdatedDate =  ?param1  WHERE UserID=  ?param2  AND Email =  ?param3  AND Status = 2]
> 2007-06-13 22:36 :48,451 Registering trigger statement [stiInsertUser] to
> cache model [User.cacheUser]
> 2007-06-13 22:36:48,498 Statement Id: [stsGetOnEmail] PreparedStatement :
> [SELECT         UserID, Firstname, Lastname, City, Description, Email,
> AES_DECRYPT(Password, Salt) AS Password, Salt, Company, Question, Answer,
> LoginAttempts, LastLoginDate, Status, CreatedDate, UpdatedDate       FROM
> users WHERE Email =  ?param0]
> 2007-06-13 22:36 :48,513 Statement Id: [stsGetOnEmail] Parameters: [
> ?param0=[value,1]]
> 2007-06-13 22:36 :48,513 Statement Id: [stsGetOnEmail] Types: [?param0=[String,
> System.String]]
> 2007-06-13 22:36 :48,529 Cache miss using key '595483856|-9223372036473027192'
>
> 2007-06-13 22:36 :48,732 Open Connection "15361084" to "MySQL, MySQLprovider
> 5.0.6.0".
> 2007-06-13 22:36 :48,748 Cache object 'System.Object' using key
> '595483856|-9223372036473027192'
> 2007-06-13 22:36 :48,763 Close Connection "15361084" to "MySQL, MySQLprovider
> 5.0.6.0".
> 2007-06-13 22:36:48,763 Statement Id: [stsGetOnEmail] PreparedStatement :
> [SELECT         UserID, Firstname, Lastname, City, Description, Email,
> AES_DECRYPT(Password, Salt) AS Password, Salt, Company, Question, Answer,
> LoginAttempts, LastLoginDate, Status, CreatedDate, UpdatedDate       FROM
> users WHERE Email =  ?param0]
> 2007-06-13 22:36 :48,763 Statement Id: [stsGetOnEmail] Parameters: [
> ?param0=[value,1]]
> 2007-06-13 22:36 :48,763 Statement Id: [stsGetOnEmail] Types: [?param0=[String,
> System.String]]
> 2007-06-13 22:36:48,763 Retrieved cached object 'System.Object' using key
> '595483856|-9223372036473027192'
> 2007-06-13 22:36:50,591 Statement Id: [stsGetOnEmail] PreparedStatement :
> [SELECT         UserID, Firstname, Lastname, City, Description, Email,
> AES_DECRYPT(Password, Salt) AS Password, Salt, Company, Question, Answer,
> LoginAttempts, LastLoginDate, Status, CreatedDate, UpdatedDate       FROM
> users WHERE Email =  ?param0]
> 2007-06-13 22:36 :50,591 Statement Id: [stsGetOnEmail] Parameters: [
> ?param0=[value,1]]
> 2007-06-13 22:36 :50,591 Statement Id: [stsGetOnEmail] Types: [?param0=[String,
> System.String]]
> 2007-06-13 22:36 :50,591 Retrieved cached object 'System.Object' using key
> '595483856|-9223372036473027192'
>
>
>
>
>
> Mvh Kenneth Olsen
>
>
>