Hallo
I am trying to configure JTA transaction manager without container (standalone)
when I use DataSourceTransactionManager rollback is successful, with JtaTransactionManager there is no rollback
I have tested on derby EmbeddedXADataSource40 and H2 org.h2.jdbcx.JdbcDataSource
problem may be in: DataSourceUtils.doGetConnection - it calls for normal connection, not for xaConnection:
Connection con = dataSource.getConnection();
thanks for help
here are java test and spring config:
XaTest-context.xml.txtXaTest.java.txt
Code:DataSourceUtils.doGetConnection(DataSource) line: 101 DataSourceUtils.getConnection(DataSource) line: 79 JdbcTemplate.execute(PreparedStatementCreator, PreparedStatementCallback<T>) line: 572 JdbcTemplate.update(PreparedStatementCreator, PreparedStatementSetter) line: 786 JdbcTemplate.update(String, PreparedStatementSetter) line: 842 JdbcTemplate.update(String, Object...) line: 850 SimpleJdbcTemplate.update(String, Object...) line: 249 XaTest$1.doInTransactionWithoutResult(TransactionStatus) line: 108 XaTest$1(TransactionCallbackWithoutResult).doInTransaction(TransactionStatus) line: 33 TransactionTemplate.execute(TransactionCallback<T>) line: 130 XaTest.testTransactionRollback() line: 103
this is test:
when I use DataSourceTransactionManager rollback is successful, with JtaTransactionManager there is no rollbackCode:@Test public void testTransactionRollback() throws IOException { try { sqlScriptProcessor.process(); } catch (IOException e) { throw new RuntimeException(e); } try { transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { simpleJdbcTemplate .update("insert into PERSON (FIRST_NAME, LAST_NAME) values (?, ?)", "Bolek", "Lolek"); System.out.println("inserted=================="); status.setRollbackOnly(); throw new RuntimeException("will rollback?"); } }); } catch (RuntimeException e) { // TODO Auto-generated catch block e.printStackTrace(); } List<Map<String, Object>> lPersonMaps = simpleJdbcTemplate .queryForList("SELECT * FROM PERSON"); logger.info("size=============================: " + lPersonMaps.size()); assertEquals( "Should be 2 persons inserted from script", 2, lPersonMaps.size()); }
this is txManager config:
Code:<!-- <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> --> <!-- <property name="dataSource" ref="dataSource"/> </bean> --> <bean id="AtomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close"> <property name="forceShutdown" value="false" /> </bean> <bean id="AtomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp"> <property name="transactionTimeout" value="300" /> </bean> <bean id="JtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManager" ref="AtomikosTransactionManager" /> <property name="userTransaction" ref="AtomikosUserTransaction" /> </bean>


Reply With Quote
