6 Replies Latest reply on Mar 5, 2013 9:03 AM by hasan serdar

    Trying to Get Second Level Cahce Entities

    hasan serdar Newbie



      I am a newbie in Jboss and Infinispan and this is my first post


      I am interested in infinispan cahce and trying to learn its capabilities and use cases. Trying to understand what is going inside second-level-cache for hibernate. I am using JBoss "jboss-as-web-7.0.2.Final" and standalone.bat.


      After a few days of searching, finally I could set the required configurations and inject the infinispan cache container to my code as follows:


      public class InfinispanManager<K, V> {
        private org.infinispan.manager.CacheContainer container;
        private org.infinispan.Cache<K, V> cache;
        public void start() {
          this.cache = this.container.getCache("entity");
        public org.infinispan.Cache<K, V> getCache()
                  return cache;


      I persist my @Cachable @Entity KVPair bean as:


      kvPair = new KVPair(key, value);


      I inject the infinispanManager as:


      private InfinispanManager<Object,Object> manager;

      But entity cache always seems empty (After a
      entityManager.persist(kvPair) ) when I look as below:




      Is my approach is correct ? Am I missing something ?


      Here is my persistence.xml persistence-unit


         <persistence-unit name="bmtDatabase">
             <!-- the datasource JNDI name as it is configured in the Application Server config files -->
                <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.JndiInfinispanRegionFactory" />
                <property name="hibernate.cache.infinispan.cachemanager" value="java:jboss/infinispan/container/hibernate" />
                <property name="hibernate.hbm2ddl.auto" value="create-drop" />
                <property name="hibernate.show_sql" value="true" />


      Here is my standalone.xml hibernate cahce container:


              <subsystem xmlns="urn:jboss:domain:infinispan:1.0" default-cache-container="hibernate">
                  <cache-container name="hibernate" default-cache="local-query" jndi-name="java:jboss/infinispan/container/hibernate">
                      <local-cache name="entity">
                          <eviction strategy="LRU" max-entries="10000"/>
                          <expiration max-idle="100000"/>
                      <local-cache name="local-query">
                          <eviction strategy="LRU" max-entries="10000"/>
                          <expiration max-idle="100000"/>
                      <local-cache name="timestamps">
                          <eviction strategy="NONE"/>


      And this is the tricky part. I should include the infinispan dependicy to my deployment by manifest.mf. I do that by maven in my pom.xml as below:


                     <!-- Java EE 6 doesn't require web.xml, Maven needs to catch
                        up! -->
                                                <Dependencies>org.infinispan export</Dependencies>


      This post is a question for me and I hope the examples above also may be helpful for someone else.