Atomikos Forum

Transaction Issue - Using Atomikos

I am using Atomikos to achieve the global transaction outside the container.

Scenario:
Move data from table-1 on DB1 to table-2 on DB2. This is the insert on DB2.
Update table-1 on DB1 with the successful flag.
Steps above should be part of the same transaction.

Approach for testing:
I am using a class that extends AbstractTransactionalTestNGSpringContextTests. (TestNG and Spring)
Got DB1 simpleJdbcTemplate, DB2 simpleJdbcTemplate and the writer (that uses JdbcDao) through ApplicationContext.
The transaction attribute on the test method i tried with are "REQUIRES_NEW" and "SUPPORTS".
The transaction attribute on the Dao method i tried with are "didn't specify anything and "SUPPORTS".

Results:
Data gets inserted into table-2 on DB2.
Table-1 on DB1 does not get updated. (Issue.... test fails)
Message on the console is "Rolled back transaction after test execution for test context".

Questions:
Shouldn't it rollback the data from table-2 on DB2, since the test failed?
Am i missing something while using the transaction attributes?
Also, when i count the number of records on table-1 on DB1 or DB2 in the writer then it returns "0" even though it has records.

Please let me know if you have any suggestions.

Thank you,
SpringForever
springforever Send private email
Friday, October 03, 2008
 
 
Here is the the use case and the environment information.
-Spring Batch
-Oracle 10 (DB1 and DB2 are XA Compliant and Configured)
-TestNG
-write method below uses Dao, which i tried with different transaction attributes.

TestClass
{
@BeforeClass
public void init() {        
    sourceJdbcTemplate = (SimpleJdbcTemplate) this.applicationContext.getBean("sourceJdbcTemplate");
    targetJdbcTemplate = (SimpleJdbcTemplate) this.applicationContext.getBean("targetJdbcTemplate");
    
    testProductionLoadItemWriter = (ProductionLoadItemWriter) this.applicationContext.
            getBean("productionItemWriterRef");              
}



@Transactional(propagation=Propagation.REQUIRES_NEW)
@Test
public void testInsert() throws Exception
{                     
    //This method inserts data in table-2 on DB2 and updates data in table-1 on DB1
    //Also, it gets the count of data in table-1 and table-2
    testProductionLoadItemWriter.write(productionLoadVOInsert);    //Count from table-1 and table-2 retruns "0".

    logger.info("testInsert() After write");

    int countTargetInsertRows = targetJdbcTemplate.queryForInt(sqlTargetInsertRowCount);        
    assertThat(countTargetInsertRows, equalTo(1));    //Assertion met 
    
    int countSourceAuditUpdateRows = sourceJdbcTemplate.queryForInt(sqlSourceUpdateCount);
    assertThat(countSourceAuditUpdateRows, equalTo(1)); //Assetion fails
    
    System.out.printf("***** testInsert() Transaction active: %s",TransactionSynchronizationManager.isActualTransactionActive());
}     
}
springforever Send private email
Friday, October 03, 2008
 
 
I figured.... Issue is not with the transaction. I will post the solution and the cause once i get to the root of it.

Thank you.
springforever Send private email
Friday, October 03, 2008
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics