나는 아직 이해하지 못했던 점이 있다고 생각한다. 내가 클래스 마녀가 내가 내 DAO는 유일한 객체가 캐시에 넣어, 내가기준을 가진 Hibernate 질의 캐시
@Override
public Pays read(String nomPays) {
Criteria criteria = super.getSession().createCriteria(Pays.class);
criteria.setFetchMode("pc", FetchMode.JOIN);
criteria.setFetchMode("ps", FetchMode.JOIN);
criteria.setFetchMode("kf", FetchMode.JOIN);
criteria.add(Restrictions.eq("nom", nomPays));
criteria.setCacheable(true);
Pays p=(Pays) criteria.uniqueResult();
return p; }
실제로 서비스 계층에서 호출 기능을 한
public class Pays implements Serializable{
private static final long serialVersionUID = -8767337896773261244L;
/**
* the id of the country
*/
private long id;
/**
* name of the country
*/
private String nom;
/**
* The region of the country
*/
private Region region;
/**
* Relations between a country and a composant
*/
private Set<PaysComposants> pc = new HashSet<PaysComposants>(0);
/**
* Relations between a country and a service
*/
private Set<PaysServices> ps = new HashSet<PaysServices>(0);
/**
* Relations between a country and some keys figures
*/
private Set<KeyFigure> kf = new HashSet<KeyFigure>(0);
속성에 요소의 3 개 컬렉션이 유일한 pays p, 다른 컬렉션 pc, ps 및 kf는 캐시에 저장되지 않습니다. 여기
내 ehCache.xml입니다
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
monitoring="autodetect" dynamicConfig="true">
<defaultCache maxElementsInMemory="100000" eternal="false"
timeToIdleSeconds="3600" timeToLiveSeconds="3600" overflowToDisk="true" />
<cache name="org.hibernate.cache.internal.StandardQueryCache"
maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="3600"
timeToLiveSeconds="3600">
</cache>
<cache name="org.hibernate.cache.spi.UpdateTimestampsCache"
maxElementsInMemory="10000" eternal="true">
</cache>
내 최대 절전 모드 속성
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="current_session_context_class">thread</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_structured_entries">true</prop>
<prop key="hibernate.cache.generate_statistics">true</prop>
<prop key="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</prop>
<prop key="hibernate.cache.region.factory_class">
org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
</prop>
<prop key="hibernate.cache.provider_configuration_file_resource_path">
applicationContext-ehCache-entity.xml
</prop>
</props>
</property>
내 받는다는 의존성
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>4.2.0.Final</version>
</dependency>
내가 어떻게 달성 할 수 있습니까? n + 1 select를 피하기 위해 FetchMde.Join을 사용합니다. 실제로 Pay는 하나의 select에로드됩니다. 감사합니다.
이미 게터에 각 개체에'@Cache (사용 = CacheConcurrencyStrategy.READ_WRITE)를'추가 : – user1310305
스프링 캐싱이나 EHCaching을 사용하고 있습니까? –
EhCaching을 사용하고 있습니다 – user1310305