Hello,
I've been banging my head against the wall for a few days with this issue.
We are trying to implement Hibernate's second-level cache, using Infinispan. The application is running on JBoss AS 6, and using JTA transactions.
On our persistence.xml we have:
Code:
...
<!-- JTA configurations -->
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup" />
<property name="current_session_context_class" value="jta" />
<!-- Infinispan configurations -->
<property name="hibernate.cache.use_second_level_cache" value="true" />
<property name="hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.InfinispanRegionFactory"/>
<property name="hibernate.cache.infinispan.cachemanager" value="java:CacheManager/entity"/>
...
as defined here: https://docs.jboss.org/author/display/ISPN/Using+Infinispan+as+JPA-Hibernate+Second+Level+Cache+Provider
On our understanding this is the kind of cache that we need in order to do the following:
Use case one: We have records on a Database which will hold reference data. This data won't be changed for long periods of time (we hope :) ).
We want to cache these records as they are likely to be queried a lot. And as users query this data there won't be a need to go to the DB, since it should be cached.
For this case, is the cache type query cache, or entity cache? Being the query always the same, my understanding it's query cache as que query is supposed to return always the same results.
My query:
Code:
List<MyEntity> list = session.createCriteria(MyEntity.class)
.add(Restrictions.eq("id", 1))
.setCacheable(true)
.list();
Use case two: A user gets a specific record from the DB, and he might update it. We would like this entity (or list of entities) to be saved on the user's session (login session) cache so if he updated this entity on the client, we wouldn't need need to make a select before the update. In this case, since we are saving specific entities, it's considered entity caching, right? If we want to store the
For that we're using:
Code:
@Cacheable (true)
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
public class MyEntity implements Serializable
{
...
}
Am I making these assumptions correctly? If not, what is the approach here? I gues I'm making a big mess out of this.