hibernate loadAll 开启二级缓存

hibernate配置文件:
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>  
<prop key="hibernate.cache.use_query_cache">true</prop>

hibernate Bean配置文件:
@Entity 
@Cache(usage=CacheConcurrencyStrategy.READ_ONLY)

或者,class里面加上
<cache region="roleTypeEhCache" usage="read-write" />

DaoImpl:
	public List<RoleType> loadRoleType(){
		HibernateTemplate template = getHibernateTemplate();
		template.setCacheQueries(true);
		return template.loadAll(RoleType.class);
	}

你可能感兴趣的:(java,Hibernate,bean,cache)