Announcement Announcement Module
Collapse
No announcement yet.
Jboss Cache and Transactions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Jboss Cache and Transactions

    I am having problem with integrating Jboss Cache with Spring. The problem is that I can’t integrate Jboss Cache with on going transaction, which causes the cache to be inconsistent when the transaction is rollbacked. I can't configure Jboss Cache to rollback. The cache is required to store simple POJO's which are not entities managed by Hibernate
    For hibernate I am using JTA Transaction.

    The application is bases on Spring 2.5 , Hibernate 3.3 , Jboss Cache 3.0 and Jboss AS 5.0.
    I would appreciate any help on this issue or working example.

    Code:
    <bean id="hibernateSessionFactory"
            class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    
        <property name="dataSource" ref="dataSourceJndi" />
        <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect
            </prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.format_sql">false</prop>
            <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory
            </prop>
    
            <prop key="hibernate.transaction.manager_lookup_class">
                org.hibernate.transaction.JBossTransactionManagerLookup</prop>
    
            <prop key="hibernate.cache.region.factory_class">
                org.hibernate.cache.jbc2.SharedJBossCacheRegionFactory</prop>
                    
            <prop key="hibernate.cache.region.jbc2.cfg.shared">mvcc.xml</prop>
    
        <aop:aspectj-autoproxy />
    
        <bean id="transactionManager"
            class="org.springframework.transaction.jta.JtaTransactionManager">
        </bean>
    
        <tx:annotation-driven transaction-manager="transactionManager" />

    Code:
    Transactional(propagation = Propagation.REQUIRES_NEW)
        
    public void add(Product p) {
    
            getHibernateTemplate().save(p);
            MBeanServer server = MBeanServerLocator.locateJBoss();
            ObjectName on = new ObjectName("jboss.cache:service=Cache2");
            CacheJmxWrapperMBean cacheWrapper = (CacheJmxWrapperMBean) MBeanServerInvocationHandler
                .newProxyInstance(server, on, CacheJmxWrapperMBean.class, false);
            cache = cacheWrapper.getCache();
    
            PojoCache pc = new PojoCache();
            pc.setId(p.getId());
            pc.setBar(1);        
            
            cache.put(pc);       
    
            Date date = new Date();
            if (date.getTime() % 10 == 0) {
                throw new RuntimeException();
            }
    }
    Code:
    <datasources>
      <local-tx-datasource>
        <jndi-name>DS</jndi-name>
        <connection-url>jdbc:postgresql://192.168.1.1/postgres</connection-url>
        <driver-class>org.postgresql.Driver</driver-class>
        [....]
      </local-tx-datasource> 
    
    </datasources>
    Regards,
    Mike
    Last edited by swwis_me; Nov 27th, 2008, 03:46 AM.
Working...
X