1、EhCache所需要的jar包:
ehcache-2.7.0.jar
slf4j-api-1.6.6.jar
slf4j-jdk14-1.6.6.jar
2、ehcache.xml 配置
新建ehcache.xml文件,添加如下配置
<ehcache>
<defaultCache maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="1000"
timeToLiveSeconds="1000"
overflowToDisk="false"
memoryStoreEvictionPolicy="LRU"/>
</ehcache>
3、User.hbm.xml 配置
<class name="User" table="TB_USER">
<cache usage="read-write"/>
<id name="uid" column="UID">
<generator class="native"></generator>
</id>
<property name="name" column="NAME" type="string"></property>
<property name="sex" column="SEX" type="string"></property>
</class>
4、hibernate.cfg.xml 配置
<!-- 指定cache实现类 -->
<property name="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</property>
<!-- 启用二级缓存 -->
<property name="hibernate.cache.use_second_level_cache">true</property>
<!-- 启用查询缓存 -->
<property name="hibernate.cache.use_query_cache">true</property>
<!-- 指定EhCache配置文件 -->
<property name="hibernate.cache.provider_configuration_file_resource_path">ehcache.xml</property>
EhCache 与 Hibernate 环境配置
猜你喜欢
转载自hospop.iteye.com/blog/1844371
今日推荐
周排行