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, MySQL
provider 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, MySQL
provider 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