二级缓存使用步骤:

  1.拷贝jar包

  ssh架构之hibernate(四)二级缓存

  2.配置Hibernate.cfg.xml文件

  a.#开启二级缓存
  hibernate.cache.use_second_level_cache=true
  b.#添加一个二级缓存的供应商(实现类)
  hibernate4的配置
  hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
  hibernate3的配置
  hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
  c.#开启查询缓存
  hibernate.cache.use_query_cache=true
  d.配置那个domain需要二级缓存(最好添加在映射文件后)
    <class-cache class="com.hibernate.day01.model.Product" usage="read-write" />

   3.测试二级缓存

  ssh架构之hibernate(四)二级缓存

  类里面集合的二级缓存配置:

  配置Hibernate.cfg.xml文件添加: <collection-cache usage="read-only" collection="com.hibernate.day01.model.ProductDir.products"/>
  ssh架构之hibernate(四)二级缓存

相关文章:

  • 2022-12-23
  • 2021-11-19
  • 2021-07-07
  • 2021-11-17
  • 2022-01-05
  • 2021-08-20
  • 2021-04-13
猜你喜欢
  • 2021-09-17
  • 2021-08-21
  • 2022-02-23
  • 2022-12-23
  • 2021-04-12
相关资源
相似解决方案