Hibernate4和Spring4-secondlevelcaching不使用一对多映射
我有一个使用Hibernate4和Spring4的应用程序,我有两个表,它们之间有一对多的关联,但是二级缓存不起作用,我对这些类做了如下注释 头等舱Hibernate4和Spring4-secondlevelcaching不使用一对多映射,spring,hibernate,caching,Spring,Hibernate,Caching,我有一个使用Hibernate4和Spring4的应用程序,我有两个表,它们之间有一对多的关联,但是二级缓存不起作用,我对这些类做了如下注释 头等舱 @Entity @Table(name = "UN_COURSE_INFORMATION", catalog = "ED") @Cache(usage=CacheConcurrencyStrategy.READ_WRITE, region="courses") public class CourseInformation e
@Entity
@Table(name = "UN_COURSE_INFORMATION", catalog = "ED")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE, region="courses")
public class CourseInformation extends AbstractEntity {
......
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "CATEGORY_ID", nullable = false)
@JsonBackReference
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
private CourseCategory courseCategory;
// other fields and getter setters
}
二等舱
@Entity
@Table(name = "UN_COURSE_CATEGORY", catalog = "ED")
@JsonIgnoreProperties({ "hibernateLazyInitializer", "handler" })
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE, region="courses")
public class CourseCategory extends AbstractEntity {
......
@OneToMany(fetch = FetchType.EAGER, mappedBy = "courseCategory")
@JsonManagedReference
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
private Set<CourseInformation> courseInformations = new HashSet<CourseInformation>(
0);
// other fields and getter setters
}
@实体
@表(name=“UN\U课程\类别”,catalog=“ED”)
@JsonIgnoreProperties({“HibernateLazInitializer”,“handler”})
@缓存(用法=cacheconcurrentystrategy.READ\u WRITE,region=“courses”)
公共类课程类别扩展了AbstractEntity{
......
@OneToMany(fetch=FetchType.EAGER,mappedBy=“courseCategory”)
@JsonManagedReference
@缓存(用法=CacheConcurrencyStrategy.READ\u WRITE)
私有集课程信息=新哈希集(
0);
//其他字段和getter setter
}
Spring HIbernate缓存配置
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<!-- <prop key="hibernate.hbm2ddl.auto">update</prop> -->
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
</prop>
<prop key="net.sf.ehcache.configurationResourceName">ouehcache.xml</prop>
<prop key="hibernate.generate_statistics">true</prop>
</props>
</property>
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
monitoring="autodetect" dynamicConfig="true">
<diskStore path="java.io.tmpdir/ehcache" />
<defaultCache maxEntriesLocalHeap="10000" eternal="false"
timeToIdleSeconds="120" timeToLiveSeconds="1200" diskSpoolBufferSizeMB="30"
maxEntriesLocalDisk="10000000" diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU" statistics="true">
<persistence strategy="localTempSwap" />
</defaultCache>
<cache name="courses" maxEntriesLocalHeap="100" eternal="false"
timeToIdleSeconds="5" timeToLiveSeconds="1200">
<persistence strategy="localTempSwap" />
</cache>
<cache name="org.hibernate.cache.internal.StandardQueryCache"
maxEntriesLocalHeap="5" eternal="false" timeToLiveSeconds="1200">
<persistence strategy="localTempSwap" />
</cache>
<cache name="org.hibernate.cache.spi.UpdateTimestampsCache"
maxEntriesLocalHeap="5000" eternal="true">
<persistence strategy="localTempSwap" />
</cache>
</ehcache>
org.hibernate.dialogue.mysql5dialogue
${hibernate.show_sql}
符合事实的
符合事实的
org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
ouehcache.xml
符合事实的
chcache配置
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<!-- <prop key="hibernate.hbm2ddl.auto">update</prop> -->
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
</prop>
<prop key="net.sf.ehcache.configurationResourceName">ouehcache.xml</prop>
<prop key="hibernate.generate_statistics">true</prop>
</props>
</property>
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
monitoring="autodetect" dynamicConfig="true">
<diskStore path="java.io.tmpdir/ehcache" />
<defaultCache maxEntriesLocalHeap="10000" eternal="false"
timeToIdleSeconds="120" timeToLiveSeconds="1200" diskSpoolBufferSizeMB="30"
maxEntriesLocalDisk="10000000" diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU" statistics="true">
<persistence strategy="localTempSwap" />
</defaultCache>
<cache name="courses" maxEntriesLocalHeap="100" eternal="false"
timeToIdleSeconds="5" timeToLiveSeconds="1200">
<persistence strategy="localTempSwap" />
</cache>
<cache name="org.hibernate.cache.internal.StandardQueryCache"
maxEntriesLocalHeap="5" eternal="false" timeToLiveSeconds="1200">
<persistence strategy="localTempSwap" />
</cache>
<cache name="org.hibernate.cache.spi.UpdateTimestampsCache"
maxEntriesLocalHeap="5000" eternal="true">
<persistence strategy="localTempSwap" />
</cache>
</ehcache>
请尽快提出解决方案,谢谢。您如何测试它是否正常工作?第二级缓存仅适用于通过ID获取的对象,如果您希望它能够处理查询,则默认情况下不会,因为您必须指示查询可缓存。我正在尝试获取所有课程的列表,并再次获取类别列表