0 Replies Latest reply on Sep 27, 2012 12:41 AM by prashanth.kudipudi

    How Hibernate second level cache behaviours when one node in the server is down:

    prashanth.kudipudi

      Hi,

       

      I am using Infinispan as a Hibernate second level cache.

       

      I am using Jboss as6, Where 2 node are created i.e node1 and node2 which will forms a cache cluster.

       

      Here is my doubt: When a node in the cache cluster was restarted and tried to load an entity which was already cached, whether it will load from the existing cache or it will be loaded from the database?

       

      In my case I have loaded an entity with Id 1 from the node1. when I tried to loaded same entity from the node2 it got loaded from cache, but when I have restarted node2 entity is got loaded from the database. So what additional configuration need to be done to load the entity from the existing cache even though node was down.

       

      Below is my configuration which I was using for the project:

       

      framework Versions used for the project: Spring 3.0, Hibernate 3.6, infinispan 4.2 and Jboss as6 as application sever.

       

      1) In the infinispan-config.xml, I have set the value of maxIdle attribute of <expiration> tag to "-1". 

       

      2) In the applicationContext.xml, Session Factory is configured as shown below.

       

      <bean id="sessionFactory" 
              class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" 
              p:dataSource-ref="dataSource"
              p:configurationClass="org.hibernate.cfg.AnnotationConfiguration"
              p:packagesToScan="com.demo.entity">
       
             <property name="hibernateProperties">
             <props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                    <prop key="hibernate.show_sql">true</prop>
                    <prop key="hibernate.format_sql">true</prop>
                    <prop key="hibernate.hbm2ddl.auto">update</prop>

       

                    <prop key="hibernate.cache.use_second_level_cache">true</prop>
                    <prop key="hibernate.cache.use_query_cache">true</prop>
                    <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.infinispan.JndiInfinispanRegionFactory</prop>
                    <prop key="hibernate.cache.infinispan.cachemanager">java:CacheManager/entity</prop>
              
                    <prop key="hibernate.cache.infinispan.query.cfg">replicated-query</prop>
                    <prop key="hibernate.cache.infinispan.entity.cfg">replicated-entity</prop>
                    <prop key="hibernate.cache.infinispan.collection.cfg">replicated-entity</prop>

              </props>
             </property>
      </bean>

      Thanks in advance,
      Prashanth K.