0 Replies Latest reply on Jun 10, 2009 1:09 PM by kevinconaway

    Hibernate Second Level Cache Not Persisting to Database

      I have JBoss Cache 2 setup as my second level cache in a two node cluster. I see that changes from one node are replicated to the other node OK but they are not being persisted into the actual database, they seem to be sitting in the second level cache. I checked the org.jboss.cache.DataContainerImpl MBean and saw that the replicated object is there.

      Why isn't the replicated object being persisted to the database?

      Hibernate Spring Config:

      <tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
      
       <bean id="annotationTransactionAspect" factory-method="aspectOf" class="org.springframework.transaction.aspectj.AnnotationTransactionAspect" lazy-init="true">
       <property name="transactionManager" ref="transactionManager"/>
       </bean>
      
       <bean id="hibernateDaoFactory" class="com.solers.vulcan.dao.impl.HibernateDAOFactory" scope="singleton" lazy-init="true">
       <property name="sessionFactory" ref="sessionFactory" />
       </bean>
      
       <bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/>
      
       <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" lazy-init="true">
       <property name="userTransaction" ref="jotm"/>
       </bean>
      
       <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" scope="singleton" lazy-init="true">
       <property name="annotatedClasses" ref="hibernateClasses"/>
       <property name="hibernateProperties" ref="hibernateProperties"/>
       <property name="dataSource" ref="dataSource" />
       <property name="jtaTransactionManager" ref="jotm"/>
       </bean>
      
       <bean id="hibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
       <property name="properties">
       <props>
       <prop key="hibernate.show_sql">false</prop>
       <prop key="hibernate.connection.autocommit">false</prop>
       <prop key="hibernate.connection.shutdown">true</prop>
       <prop key="hibernate.dialect">org.hibernate.dialect.DerbyDialect</prop>
       <prop key="hibernate.jdbc.batch_size">25</prop>
       <prop key="hibernate.default_schema">${jdbc.user}</prop>
       <prop key="hibernate.cache.use_second_level_cache">true</prop>
       <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.jbc2.SharedJBossCacheRegionFactory</prop>
       <prop key="hibernate.cache.region_prefix">MSG</prop>
       <prop key="hibernate.cache.region.jbc2.cfg.shared">cache-config.xml</prop>
       <prop key="hibernate.transaction.factory_class">org.springframework.orm.hibernate3.SpringTransactionFactory</prop>
       <prop key="hibernate.transaction.manager_lookup_class">org.springframework.orm.hibernate3.LocalTransactionManagerLookup</prop>
      
       </props>
       </property>
       </bean>


      cache-config.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      
      <server>
       <mbean code="org.jboss.cache.TreeCache"
       name="jboss.cache:service=TreeCache">
      
       <attribute name="NodeLockingScheme">PESSIMISTIC</attribute>
       <attribute name="IsolationLevel">READ_COMMITTED</attribute>
       <attribute name="CacheMode">REPL_SYNC</attribute>
      
       <!-- Name of cluster. Needs to be the same for all members, in order to find each other -->
       <attribute name="ClusterName">pessimistic-shared</attribute>
      
       <attribute name="ClusterConfig">
       <config>
       <TCP
       stats="true"
       bind_addr="${jgroups.tcp.bind_addr}"
       start_port="${jgroups.tcp.start_port}" />
      
       <TCPPING
       stats="true"
       timeout="3000"
       initial_hosts="${jgroups.tcpping.initial_hosts:localhost[7800]}"
       port_range="${jgroups.tcpping.port_range}"
       num_initial_members="${jgroups.tcpping.num_initial_members}"/>
      
       <VERIFY_SUSPECT timeout="1500"/>
      
       <pbcast.NAKACK
       use_mcast_xmit="false"
       gc_lag="0"
       retransmit_timeout="300,600,1200,2400,4800"
       discard_delivered_msgs="true"/>
      
       <pbcast.STABLE
       stability_delay="1000"
       desired_avg_gossip="50000"
       max_bytes="400000"/>
      
       <pbcast.GMS
       print_local_addr="true"
       join_timeout="3000"
       shun="true"
       view_bundling="true"/>
      
       <pbcast.STREAMING_STATE_TRANSFER/>
      
       <FD_SOCK/>
      
       <FD
       timeout="10000"
       max_tries="5"
       shun="true"/>
       </config>
       </attribute>
      
       <attribute name="FetchInMemoryState">true</attribute>
       <attribute name="StateRetrievalTimeout">20000</attribute>
       <attribute name="SyncReplTimeout">20000</attribute>
       <attribute name="LockAcquisitionTimeout">15000</attribute>
      
       <attribute name="UseRegionBasedMarshalling">true</attribute>
       <!-- Must match the value of "useRegionBasedMarshalling" -->
       <attribute name="InactiveOnStartup">true</attribute>
      
       <attribute name="EvictionPolicyConfig">
       <config>
       <attribute name="wakeUpIntervalSeconds">5</attribute>
       <!-- Name of the DEFAULT eviction policy class. -->
       <attribute name="policyClass">org.jboss.cache.eviction.LRUPolicy</attribute>
       <!-- Cache wide default -->
       <region name="/_default_">
       <!-- Evict LRU node once we have more than this number of nodes -->
       <attribute name="maxNodes">10000</attribute>
       <!-- And, evict any node that hasn't been accessed in this many seconds -->
       <attribute name="timeToLiveSeconds">1000</attribute>
       <!-- Don't evict a node that's been accessed within this many seconds.
       Set this to a value greater than your max expected transaction length. -->
       <attribute name="minTimeToLiveSeconds">120</attribute>
       </region>
       <!-- Don't ever evict modification timestamps -->
       <region name="/TS" policyClass="org.jboss.cache.eviction.NullEvictionPolicy"/>
       </config>
       </attribute>
      
       </mbean>
      </server>


      Thanks