transaction failed to rollback
sridhar_ratna Sep 16, 2009 5:34 AMHi,
I am using jboss cahe 3.1 core and using jbdm as persistent storage and jboss jta 4.1 as transaction manager.
Problem is even if i say rollback(0 it didnt have any effect.
Simmple code i have written as
package com.test; import javax.transaction.NotSupportedException; import javax.transaction.SystemException; import org.jboss.cache.Cache; import org.jboss.cache.CacheFactory; import org.jboss.cache.DefaultCacheFactory; import org.jboss.cache.Fqn; import org.jboss.cache.Node; import org.jboss.cache.transaction.JBossStandaloneJTAManagerLookup; import com.arjuna.ats.jta.TransactionManager; public class CacheMgr { public String CACHE_CFG_PATH = "src/jboss-cache.xml"; /** JBoss Cache instance. */ private Cache<Long, Object> cache = null; JBossStandaloneJTAManagerLookup jtaLookupMgr = null; javax.transaction.TransactionManager txnManager = null; /** Singleton instance. */ private static CacheMgr instance = null; public static CacheMgr getInstance() { if (instance == null) { instance = new CacheMgr(); } return instance; } public void start() { try { CacheFactory<Long, Object> factory = new DefaultCacheFactory<Long, Object>(); cache = factory.createCache(CACHE_CFG_PATH); cache.getConfiguration().getRuntimeConfig().setTransactionManager(TransactionManager.transactionManager()); cache.create(); cache.start(); System.out.println(cache.getConfiguration().getRuntimeConfig().getTransactionManager()); } catch (Exception e) { e.printStackTrace(); } } public void stop() { if (cache != null) { cache.stop(); } } public Cache<Long, Object> getCache() { return cache; } private Node<Long, Object> createCollectionNode(String collectionPath, final Node<Long, Object> rootNode) { Fqn<String> fqn = null; Node<Long, Object> collectionNode = rootNode; final String[] pathElements = collectionPath.substring(0).split("/"); for (String pathElement : pathElements) { fqn = Fqn.fromString("/" + pathElement); if (collectionNode.hasChild(fqn)) collectionNode = collectionNode.getChild(fqn); else { collectionNode = collectionNode.addChild(fqn); } } return collectionNode; } public static void main(String[] args) { CacheMgr mgr = CacheMgr.getInstance(); mgr.start(); Cache<Long, Object> cache = mgr.getCache(); try { javax.transaction.TransactionManager tx = cache.getConfiguration().getRuntimeConfig().getTransactionManager(); tx.begin(); mgr.createCollectionNode("/test/sridhar", cache.getRoot()); tx.rollback(); } catch (NotSupportedException e) { e.printStackTrace(); } catch (SystemException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalStateException e) { e.printStackTrace(); } /*catch (RollbackException e) { e.printStackTrace(); } catch (HeuristicMixedException e) { e.printStackTrace(); } catch (HeuristicRollbackException e) { e.printStackTrace(); }*/ } }
and my config file as
<?xml version="1.0" encoding="UTF-8"?> <jbosscache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:jboss:jbosscache-core:config:3.1"> <transaction transactionManagerLookupClass="org.jboss.cache.transaction.GenericTransactionManagerLookup" syncRollbackPhase="true" syncCommitPhase="true" /> <locking isolationLevel="REPEATABLE_READ" lockParentForChildInsertRemove="false" lockAcquisitionTimeout="200000" nodeLockingScheme="mvcc" writeSkewCheck="false" useLockStriping="false" concurrencyLevel="500" /> <jmxStatistics enabled="true" /> <loaders passivation="false" shared="false"> <preload> <node fqn="/" /> </preload> <loader class="org.jboss.cache.loader.jdbm.JdbmCacheLoader" async="false" fetchPersistentState="true" ignoreModifications="false"> <properties> location=D:\\cache1 </properties> </loader> </loaders> </jbosscache>
What is the problem. Where i did the mistake.
The same problem even when i replaced code line
cache.getConfiguration().getRuntimeConfig().setTransactionManager(TransactionManager.transactionManager());
with
jtaLookupMgr = new JBossStandaloneJTAManagerLookup(); cache.getConfiguration().getRuntimeConfig().setTransactionManager(jtaLookupMgr.getTransactionManager());
Thanks,
Sridhar