Posted on 2009-11-02 14:43 
疯狂 阅读(605) 
评论(0)  编辑  收藏  所属分类: 
hibernate 
			
			
		 
		步骤:
1:配置:
 
    - <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>   
 
    -                 <prop key="hibernate.cache.use_query_cache">true</prop>  
 
 
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
 2:bean配置:
写道
@Entity 
@Cache(usage=CacheConcurrencyStrategy.READ_ONLY)
 
关于缓存策略介绍可见我的hibernate文章里面的相关内容
3,查询
    - HibernateTemplate template = getHibernateTemplate();   
 
    -         <SPAN style="COLOR: #ff0000">template.setCacheQueries(true);</SPAN>   
 
    -         List list =  template.loadAll(clazz);  
 
 
HibernateTemplate template = getHibernateTemplate();
template.setCacheQueries(true);
List list =  template.loadAll(clazz);
 二级缓存需要和查询缓存配合使用 查询缓存缓存数据的id 并通过id去二级缓存查找