emacarron / mybatis

Automatically exported from code.google.com/p/mybatis
0 stars 0 forks source link

Apply Ehcache to mybatis #150

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In JavaSE environment,I used mybatis-3.0.2.jar and 
mybatis-ehcache-1.0.0-RC1.jar to apply Ehcache.
My setting files like the below:

BlogMapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.mybatis.example.BlogMapper">
<cache type="org.mybatis.caches.ehcache.EhcacheCache"/>

<select id="selectBlogs" parameterType="string" 
resultType="org.mybatis.example.Blog">
    select * from Blog where trim(name) = #{name}
</select>
</mapper>

ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
   <diskStore path="tmpdir"/>
   <defaultCache maxElementsInMemory="1"
                 eternal="true"
                 overflowToDisk="true"/>

</ehcache>

In DB, the data that match condition have 10. But I only get a 0 size cache 
file on disk. Why? Please help me. Thanks.

Original issue reported on code.google.com by hmily...@gmail.com on 22 Oct 2010 at 9:09

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I find the cause is that the key is not serializable. 
In net.sf.ehcache.Element#isKeySerializable(), if key is not an instance of 
Serializable or null, it is not enable to record result in disk file. 
Key's object is org.apache.ibatis.cache.CacheKey. CacheKey do not implement 
Serializable interface. If CacheKey  implements Serializable interface, select 
result can be record in disk file.

Original comment by hmily...@gmail.com on 25 Oct 2010 at 1:59

GoogleCodeExporter commented 9 years ago
Hi hmilysls,
thanks for the feedback, you reported an evident defect, I tested ehcache in 
memory only.
I need to work a little on the module, stay tuned!

Original comment by simone.t...@gmail.com on 1 Nov 2010 at 12:50

GoogleCodeExporter commented 9 years ago

Original comment by simone.t...@gmail.com on 1 Nov 2010 at 12:50

GoogleCodeExporter commented 9 years ago
Hi hmilysls,
I fixed that issue on /trunk, can you check it out and verify it works before 
publishing the next release? Thanks in advance!
Simo

Original comment by simone.t...@gmail.com on 7 Nov 2010 at 5:51

GoogleCodeExporter commented 9 years ago
Hi Simo,
I checked src out from "http://mybatis.googlecode.com/svn/trunk/src". But this 
issue still exists. I look at code of org.apache.ibatis.cache.CacheKey. 
CacheKey is not Serializable. In which version, the issue is fixed? 

hmilysls

Original comment by hmily...@gmail.com on 16 Nov 2010 at 8:30

GoogleCodeExporter commented 9 years ago
Hi hmilysls,
In the trunk I'm now using the org.apache.ibatis.cache.CacheKey hashCode() as 
EHCache key, being int/Integer serializable.
BWT, you checked out from the wrong place, please follow the following simple 
steps to verify the new version of ehcache integration:

svn co https://mybatis.googlecode.com/svn/sub-projects/caches/trunk 
mybatis-caches
cd mybatis-caches
mvn install

now include the followinf dependency in your pom:

<dependency>
<groupId>org.mybatis.caches</groupId>
<artifactId>mybatis-ehcache</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>

so now you can check if the ehcache inserts go well.
Please let me know!
Simo

Original comment by simone.t...@gmail.com on 16 Nov 2010 at 8:58

GoogleCodeExporter commented 9 years ago
Hi Simo,
I have tried it. Select result can be record in disk file. The issue is solved.
Thanks for your help!
hmilysls

Original comment by hmily...@gmail.com on 16 Nov 2010 at 10:32

GoogleCodeExporter commented 9 years ago
Thanks to you for your feedbacks!!! New version will be published ASAP, stay 
tuned! :)
Simo

Original comment by simone.t...@gmail.com on 16 Nov 2010 at 10:48

GoogleCodeExporter commented 9 years ago
Issue can be closed, fixed on /trunk

Original comment by simone.t...@gmail.com on 16 Nov 2010 at 10:49