`

hibernate配置二级缓存(二级缓存配置未起作用)

阅读更多
二级缓存配置
1.添加缓存插件对应的jar包
ehcache-1.2.3.jar
commons-logging-1.1.1.jar
2.将ehcache.xml文件添加到项目的src目录下:
<ehcache>
<diskStore path="C:\\temp"/>
<defaultCache
   maxElementsInMemory="10000"
   eternal="false" 
   timeToIdleSeconds="15"
   timeToLiveSeconds="120"
   overflowToDisk="true"/> 
</ehcache>
3.开启二级缓存
<!--在hibernate.cfg.xml配置二级缓存 -->
<property name="hibernate.cache.use_second_level_cache">
true
</property>
      
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
5.指定使用二级缓存的实体类
示例:在Grade.hbm.xml文件中
<class name="entity.Grade" table="GRADE" schema="t26j">
        <cache usage="read-write"/>
</class>
注意:
[size=large]1.在测试的时候,用hibernateSessionFactory.getSession()得到session对象[/size]
如果不用session工厂则配置就不会起作用
2.使用new Configuration().configure().buildSessionFactory()
创建同一个工厂,通过这一个工厂产生多个session
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics