Announcement Announcement Module
Collapse
No announcement yet.
Transaction suspend and resume: Spring 2.0 and Jboss 4.2.1 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Transaction suspend and resume: Spring 2.0 and Jboss 4.2.1

    I am trying to simulate SPR-4077 (same as SPR-4122), which is what we are also facing using spring 2.0.4, by using naked Jboss transaction manager from jboss 4.2.1. Following is the piece of code I wrote in a servlet:
    Code:
     JtaTransactionManager jtaTm = (JtaTransactionManager) ourAppContext.getBean("transactionManager");
            jndiDS = (DataSource) ourAppContext.getBean("dataSource");
            System.out.println("TM Class: " + jtaTm.getTransactionManager().getClass());
            System.out.println("JNDI Datasource Class: " + jndiDS.getClass());
    
            // start transaction
            TransactionManager tm = jtaTm.getTransactionManager();
            System.out.println("Starting first transaction");
            tm.begin();
    
            // Retrieve a connection and insert into testJbossTrans
            Connection con1 = jndiDS.getConnection();
            Statement stmt1 = con1.createStatement();
            System.out.println("Connection's autocommit property: " + con1.getAutoCommit());
            stmt1.execute("insert into testJbossTrans values(1)");
            System.out.println("Suspending first transaction");
            Transaction trans1 = tm.suspend();
            
            // start a new transaction
            System.out.println("Starting second transaction; Connection from previous transaction not released");
            tm.begin();
    
            // Retrieve a connection and insert into testJbossTrans
            Connection con2 = jndiDS.getConnection();
            Statement stmt2 = con2.createStatement();
            stmt2.execute("insert into testJbossTrans values(2)");
            System.out.println("Marking for rollback second transaction");
            // mark for rollback and then, rollback
            tm.setRollbackOnly();
            tm.rollback();
            
            stmt2.close();
            stmt2 = null;
            System.out.println("Resuming first transaction");
            tm.resume(trans1);
    
            // mark for rollback again
            System.out.println("Marking for rollback first transaction");
            tm.setRollbackOnly();
            ResultSet rset = stmt1.executeQuery("select count(*) from testJbossTrans");
    
            while (rset.next()) {
                System.out.println("Trans-1 after suspension and using con1: id = " + rset.getInt(1));
            }
    
            // rollback and release connection
            tm.rollback();
            con1.close();
            con1 = null;
            stmt1.close();
            stmt1 = null;
    Note that I am not releasing connection back to the connection pool when I suspend the first transaction. When I begin the second inner transaction, I was expecting to see java.lang.IllegalStateException: Trying to change transaction TransactionImple < ac, BasicAction: a0359b1:4e3:4734f5c7:fc status: ActionStatus.RUNNING > in enlist! but nothing happened. Instead, the above code ran fine and gave following output: [STDOUT] TM Class: class com.arjuna.ats.jbossatx.jta.TransactionManagerDele gate
    [STDOUT] JNDI Datasource Class: class org.jboss.resource.adapter.jdbc.WrapperDataSource
    [STDOUT] Starting first transaction
    [STDOUT] Connection's autocommit property: false
    [STDOUT] Suspending first transaction
    [STDOUT] Starting second transaction; Connection from previous transaction not released
    [STDOUT] Marking for rollback second transaction
    [STDOUT] Resuming first transaction
    [STDOUT] Marking for rollback first transaction
    [STDOUT] Trans-1 after suspension and using con1: id = 1
    What am I doing wrong?
    Last edited by aggarwald; Jun 16th, 2008, 08:59 AM.

  • #2
    Once again, what I am trying to simulate is java.lang.IllegalStateException: Trying to change transaction TransactionImple < ac, BasicAction: a0359b1:4e3:4734f5c7:fc status: ActionStatus.RUNNING > in enlist! when we suspend a jboss transaction without releasing the underlying connection, so that I can understand the root cause. Earlier, we were receiving IllegalstateException on Jboss 4.2.1 when using Spring 2.0.4 and Hibernate 3.2.2, which gets resolved using spring 2.5. I believe the above code is what is executed internally by Spring/Hibernate combo. Following is my app-context file for this test case:
    Code:
    <bean id="dataSource"
        class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">
          <value>testDS</value>
        </property>
      </bean>
    
      <bean id="transactionManager"
        class="org.springframework.transaction.jta.JtaTransactionManager">
        <property name="transactionManagerName" value="java:/TransactionManager">
        </property>
        <property name="userTransactionName" value="UserTransaction"></property>
      </bean>
    Also, I am using Oracle Datasource and Oracle 10g database.

    Comment

    Working...
    X