Upgrading to version 3 didn't fix it.
I had a closer look at the cache hit statement:
Cache 'Employee.selectEmpNameCache': retrieved object
'com.pastel.ess.domain.EmpName@3'
This 3 at the end of the cache object is the value put in my ID field.
That sounds a bit cryptic, let's explain it this way:
I've got a employee with EmpID = 2 and a code = '2'
When I request this employee and he is not in the cache I would:
Select EmpID, code FROM table Where EmpID=2
And get EmpID = 2 and a code = '2'
No I do a cache hit for this same employee and it will retrieve object
'com.pastel.ess.domain.EmpName@3'
Now I got a employee with (wrong) EmpId = 3 and the (correct) Code = '2'
Why is the id/address of the cache object placed into my result object?
_____
From: Jeff Butler [mailto:jeffgbutler@gmail.com]
Sent: 16 March 2007 11:34 AM
To: user-java@ibatis.apache.org
Subject: Re: Retrieving wrong result out of the Cache.
What version of iBATIS are you using? There was a problem with caching, but
it was fixed quite a while ago.
Jeff Butler
On 3/16/07, Meindert <meindert@pastelebusiness.com> wrote:
Anyone who knows what I'm doing wrong or is encountering the same issue?
>Hi there,
My cache is returning the wrong ID, for instance the statement
Select ID from X where ID=3 is returning not 3!
Here are the code sniplets I have that are producing the wrong data (after
the cache has been populated)
Requesting the employee with diary.getDiaryEmpId()=3
EmpName empName = (EmpName) queryForObject("selectEmpName",
diary.getDiaryEmpId());
The SQL
<cacheModel id="selectEmpNameCache" type="LRU">
<flushInterval hours="12"/>
<flushOnExecute statement="updateEmployee"/>
<property name="cache-size" value="25"/>
</cacheModel>
<select id="selectEmpName" parameterClass="int" resultClass="EmpName"
cacheModel="selectEmpNameCache">
SELECT EmplMain.EmpId, CompanyId, EmplName, Surname, NickName, Code,
Email, Telephone1, Telephone2
FROM EmplMain
JOIN EmplProfile ON EmplProfile.EmpId = EmplMain.EmpId
WHERE EmplMain.EmpId=#value# AND EmplMain.IsActiveEmployee=1
</select>
Results in fetching Employee out of cache
DEBUG [http-8084-Processor22] - Cache 'Employee.selectEmpNameCache':
retrieved object 'com.pastel.ess.domain.EmpName@1'
The resulting object has as Empid 1 and not 3!
All other field values are correct.
MEINDERT HOVING
|