<hibernate-configuration>
<session-factory>
......
<!-- 开启二级缓存 -->
<property name="hibernate.cache.use_second_level_cache">true</property>
<!-- 启动"查询缓存"如果想缓存使用findall()、list()、Iterator()、createCriteria()、createQuery()等方法获得的数据结果集,必须配置此项-->
<property name="hibernate.cache.use_query_cache">true</property>
<!-- 设置二级缓存插件EHCache的Provider类-->
<!-- <property name="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</property> -->
<!-- 二级缓存区域名的前缀 -->
<!--<property name="hibernate.cache.region_prefix">test</property>-->
<!-- 高速缓存提供程序 -->
<property name="hibernate.cache.region.factory_class">
net.sf.ehcache.hibernate.EhCacheRegionFactory
</property>
<!-- Hibernate4以后都封装到org.hibernate.cache.ehcache.EhCacheRegionFactory -->
<!-- 指定缓存配置文件位置 -->
<!-- <property name="hibernate.cache.provider_configuration_file_resource_path">
ehcache.xml
</property> -->
<!-- 强制Hibernate以更人性化的格式将数据存入二级缓存 -->
<property name="hibernate.cache.use_structured_entries">true</property>
<!-- Hibernate将收集有助于性能调节的统计数据 -->
<property name="hibernate.generate_statistics">true</property>
......
</session-factory>
</hibernate-configuration>
<?xml version="1.0" encoding="UTF-8"?>
<ehcache>
<!--如果缓存中的对象存储超过指定的缓存数量的对象存储的磁盘地址-->
<diskStore path="D:/ehcache"/>
<!-- 默认cache:如果没有对应的特定区域的缓存,就使用默认缓存 -->
<defaultCache maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="300"
timeToLiveSeconds="600"
overflowToDisk="false"/>
<!-- 指定区域cache:通过name指定,name对应到Hibernate中的区域名即可-->
<cache name="cn.javass.h3test.model.UserModel"
eternal="false"
maxElementsInMemory="100"
timeToIdleSeconds="1200"
timeToLiveSeconds="1200"
overflowToDisk="false">
</cache>
</ehcache>
<class>
<!-- 设置该持久化类的二级缓存并发访问策略 read-only read-write nonstrict-read-write transactional-->
<class name="cn.java.test.model.User" table="TBL_USER">
<cache usage="read-write"/>
......
</class>
</hibernate-mapping>
**也可以用Hibernate注解配置缓存实体类**
**Java代码
@Entity
@Table
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class User implements Serializable {
private static final long serialVersionUID = -5121812640999313420L;
private Integer id;
private String name;
......
}**
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有