Note that there are some explanatory texts on larger screens.

plurals
  1. POEhCache + hibernate
    primarykey
    data
    text
    <p>I have the following problem: I have a query which return me 35 results and I would like to keep in second level cache: </p> <pre><code>public List&lt;Product&gt; 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&lt;Product&gt; products =query.list(); return products; } </code></pre> <p>My object is the following:</p> <pre><code>@Entity @Table(name="products",schema="test11") @Cacheable @Cache( usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) public class Product implements Serializable { //all setters and getters ommited: } </code></pre> <p>my ehcache.xml file is in /src/ directory:</p> <pre><code>&lt;ehcache&gt; &lt;diskStore path="java.io.tmpdir"/&gt; &lt;defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="false"/&gt; &lt;cache name="hibernate.test.org.hibernate.cache.UpdateTimestampsCache" maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"/&gt; &lt;cache name="hibernate.test.org.hibernate.cache.StandardQueryCache" maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true"/&gt; &lt;cache name="com.vanilla.objects.Product" maxElementsInMemory="300" eternal="false" overflowToDisk="false" timeToIdleSeconds="600" timeToLiveSeconds="600" /&gt; &lt;cache name="productCache" maxElementsInMemory="100" eternal="true" overflowToDisk="false" /&gt; &lt;/ehcache&gt; </code></pre> <p>and my Hibernate configuration is: </p> <pre><code>&lt;props&gt; &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.OracleDialect&lt;/prop&gt; &lt;prop key="hibernate.cache.use_second_level_cache"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.cache.use_query_cache"&gt;true&lt;/prop&gt; &lt;prop key="hibernate.cache.provider_class"&gt;net.sf.ehcache.hibernate.SingletonEhCacheProvider&lt;/prop&gt; &lt;prop key="hibernate.connection.release_mode"&gt;after_transaction&lt;/prop&gt; &lt;prop key="hibernate.cache.provider_configuration_file_resource_path"&gt;/ehcache.xml&lt;/prop&gt; &lt;/props&gt; </code></pre> <p>My problem is the following: when bringing page for first time I see the select which brings all 35 results:</p> <p>when I refresh page, instead of bringing 35 objects from cache I see 35 select statements which queries objects by id one by one.</p> <p>What's wrong? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload