2010-11-03 45 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夏爾馬