我在查找表中有一个数据列表,我正在尝试使用ehcache进行缓存。我注意到缓存正在正确填充数据,但是当我在条件查询中使用.add(Restrictions.like(“name”,“Fritz%”))时,它似乎没有达到二级缓存。有没有办法配置ehcache使用字符串值而不仅仅是Id?
查看缓存查询示例
List cats = sess.createCriteria(Cat.class)
.add( Restrictions.like("name", "Fritz%") )
.setCacheable(true)
.list();
的hibernate.cfg.xml
<!-- Enable Second-Level Cache and Query Cache Settings -->
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</property>
<property name="hibernate.generate_statistics">false</property>
实体
@Entity
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Cat implements Serializable {
private String name;
日志
stat.Statistics HQL: null, time: 1ms, rows: 0
cache.StandardQueryCache caching query results in region: org.hibernate.cache.StandardQueryCache; timestamp=5516849224093696
cache.UpdateTimestampsCache Pre-invalidating space [vehicle_trim_level]
cache.UpdateTimestampsCache Pre-invalidating space [vehicle_model]
cache.UpdateTimestampsCache Invalidating space [vehicle_model], timestamp: 5516849224110081
cache.UpdateTimestampsCache Invalidating space [vehicle_trim_level], timestamp: 5516849224110081
cache.UpdateTimestampsCache Pre-invalidating space [vehicle]
stat.ConcurrentStatisticsImpl Logging statistics....
stat.ConcurrentStatisticsImpl start time: 1346820087066
stat.ConcurrentStatisticsImpl sessions opened: 57
stat.ConcurrentStatisticsImpl sessions closed: 56
stat.ConcurrentStatisticsImpl transactions: 1211
stat.ConcurrentStatisticsImpl successful transactions: 1153
stat.ConcurrentStatisticsImpl optimistic lock failures: 0
stat.ConcurrentStatisticsImpl flushes: 1153
stat.ConcurrentStatisticsImpl connections obtained: 1212
stat.ConcurrentStatisticsImpl statements prepared: 2444
stat.ConcurrentStatisticsImpl statements closed: 2444
stat.ConcurrentStatisticsImpl second level cache puts: 540
stat.ConcurrentStatisticsImpl second level cache hits: 0
stat.ConcurrentStatisticsImpl second level cache misses: 0
stat.ConcurrentStatisticsImpl entities loaded: 125
stat.ConcurrentStatisticsImpl entities updated: 710
stat.ConcurrentStatisticsImpl entities inserted: 475
stat.ConcurrentStatisticsImpl entities deleted: 0
stat.ConcurrentStatisticsImpl entities fetched (minimize this): 0
stat.ConcurrentStatisticsImpl collections loaded: 8
stat.ConcurrentStatisticsImpl collections updated: 0
stat.ConcurrentStatisticsImpl collections removed: 0
stat.ConcurrentStatisticsImpl collections recreated: 0
stat.ConcurrentStatisticsImpl collections fetched (minimize this): 8
stat.ConcurrentStatisticsImpl queries executed to database: 719
stat.ConcurrentStatisticsImpl query cache puts: 680
stat.ConcurrentStatisticsImpl query cache hits: 494
stat.ConcurrentStatisticsImpl query cache misses: 680
stat.ConcurrentStatisticsImpl max query time: 10ms
cache.UpdateTimestampsCache Pre-invalidating space [vehicle_trim_level]
cache.UpdateTimestampsCache Invalidating space [vehicle], timestamp: 5516849228881920
cache.UpdateTimestampsCache Invalidating space [vehicle_trim_level], timestamp: 5516849228881920