2010-11-03 103 views
2

我有一个很难搞清楚如何有效地使用查询缓存标准查询以下实体选择对象时的Hibernate查询缓存导致缓存未命中是:复合ID

Criteria criteria = getCurrentSession().createCriteria(CategoryConfigurationValue.class); 
    criteria.setCacheable(true); 
    criteria.setCacheRegion("query.AllConfigurationValuesForCategoriesAndAncestors"); 
    criteria.add(Restrictions.in("primaryKey.categoryId", categoryIds)); 

    List<CategoryConfigurationValue> allCategoryConfigurationValues = criteria.list(); 

是指在执行第一次我得到了“中”查询:

Hibernate: select this_.category_id as category1_4_0_, this_.configuration_type_id as configur2_4_0_, this_.value as value4_0_ from category_configuration_values this_ where this_.category_id in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 

如果我执行它另一次我得到了很多下面的,这对我看起来像高速缓存未命中:

Hibernate: select categoryco0_.category_id as category1_4_0_, categoryco0_.configuration_type_id as configur2_4_0_, categoryco0_.value as value4_0_ from category_configuration_values categoryco0_ where categoryco0_.category_id=? and categoryco0_.configuration_type_id=? 
Hibernate: select categoryco0_.category_id as category1_4_0_, categoryco0_.configuration_type_id as configur2_4_0_, categoryco0_.value as value4_0_ from category_configuration_values categoryco0_ where categoryco0_.category_id=? and categoryco0_.configuration_type_id=? 
Hibernate: select categoryco0_.category_id as category1_4_0_, categoryco0_.configuration_type_id as configur2_4_0_, categoryco0_.value as value4_0_ from category_configuration_values categoryco0_ where categoryco0_.category_id=? and categoryco0_.configuration_type_id=? 
Hibernate: select categoryco0_.category_id as category1_4_0_, categoryco0_.configuration_type_id as configur2_4_0_, categoryco0_.value as value4_0_ from category_configuration_values categoryco0_ where categoryco0_.category_id=? and categoryco0_.configuration_type_id=? 
Hibernate: select categoryco0_.category_id as category1_4_0_, categoryco0_.configuration_type_id as configur2_4_0_, categoryco0_.value as value4_0_ from category_configuration_values categoryco0_ where categoryco0_.category_id=? and categoryco0_.configuration_type_id=? 
... 

什么可能我会丢失吗?

回答

0

虽然你们已经启用查询缓存,你需要明确地添加类CategoryConfigurationValue为可缓存,则该类的所有实例被标记为可缓存,这将解决您的问题..

  • Anantha夏尔马