Tôi có vấn đề sau đây: Tôi đã một truy vấn mà trả lại cho tôi 35 kết quả và tôi muốn giữ trong bộ nhớ cache mức độ thứ hai:ehcache + ngủ đông
public List<Product> getAllProducts() {
Session session = this.sessionfactory.getCurrentSession();
String queryString = "from com.ewave.upromotions.objects.Product product where product.active=:active";
Query query = session.createQuery(queryString);
query.setBoolean("active", true);
query.setCacheable(true);
query.setCacheRegion("productCache");
List<Product> products =query.list();
return products;
}
đối tượng của tôi là như sau:
@Entity
@Table(name="products",schema="test11")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Product implements Serializable {
//all setters and getters ommited:
}
tập tin ehcache.xml của tôi là trong/src/thư mục:
<ehcache>
<diskStore path="java.io.tmpdir"/>
<defaultCache maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="false"/>
<cache name="hibernate.test.org.hibernate.cache.UpdateTimestampsCache"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"/>
<cache name="hibernate.test.org.hibernate.cache.StandardQueryCache"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"/>
<cache name="com.vanilla.objects.Product"
maxElementsInMemory="300"
eternal="false"
overflowToDisk="false"
timeToIdleSeconds="600"
timeToLiveSeconds="600"
/>
<cache name="productCache"
maxElementsInMemory="100"
eternal="true"
overflowToDisk="false" />
</ehcache>
và cấu hình Hibernate của tôi là:
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop>
<prop key="hibernate.connection.release_mode">after_transaction</prop>
<prop key="hibernate.cache.provider_configuration_file_resource_path">/ehcache.xml</prop>
</props>
Vấn đề của tôi là như sau: khi mang trang cho lần đầu tiên tôi nhìn thấy các lựa chọn mang lại tất cả 35 kết quả:
khi tôi làm mới trang, thay vì đưa 35 đối tượng từ bộ nhớ cache Tôi thấy 35 chọn các câu lệnh truy vấn các đối tượng theo từng cái một.
Có vấn đề gì?