spring boot 默认 jpa 如何关闭缓存

我使用springboot1.5.3 默认的jpa, 即hibernate5 实现的jpa
那么请问如果我想要关闭一级缓存的话,应该怎么操作? 在application.properties里有没有现成的开关呢,感谢大家帮助,谢谢
已邀请:

wayne

赞同来自: AboutBelief

请参考C:\Users\Administrator\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\1.5.4.RELEASE\spring-boot-autoconfigure-1.5.4.RELEASE.jar!\org\springframework\boot\autoconfigure\orm\jpa
目前我还没有涉及到这块儿,所以需要你看看这几个相关的类,来分析一下如何设置
HibernateJpaAutoConfiguration
JpaBaseConfiguration
JpaProperties

xiaobaxi - Fang Oba

赞同来自: AboutBelief

一级缓存属于session级别的,它随session生命周期而存在,session销毁了一级缓存就销毁 应该通过clear evict让其失效
 
hibernate中的session,通过Session#setCacheMode(CacheMode)都是针对二级缓存的
可以参考org.hibernate.CacheMode,注释写的很明白
 
通过clear或者evict深入,可以看到最终维护的persistenceContext的实现StatefulPersistenceContext中,都是Map

mercyblitz - mercyblitz

赞同来自: AboutBelief

可以通过 
调用 SessionFactory#openStatelessSession()创建 StatelessSession
 
A stateless session does not implement a first-level cache nor interact with any second-level cache, nor does it implement transactional write-behind or automatic dirty checking, nor do operations cascade to associated instances. Collections are ignored by a stateless session. Operations performed via a stateless session bypass Hibernate's event model and interceptors. Stateless sessions are vulnerable to data aliasing effects, due to the lack of a first-level cache.

AboutBelief

赞同来自:

谢谢大家

要回复问题请先登录注册