@Test
public void testWithJtaTxManagerAndNonSpringTxManager() throws java.sql.SQLException {
Environment original = sqlSessionFactory.getConfiguration().getEnvironment();
MockDataSource mockDataSource = new MockDataSource();
mockDataSource.setupConnection(createMockConnection());
Environment nonSpring = new Environment("non-spring", new ManagedTransactionFactory(), mockDataSource);
sqlSessionFactory.getConfiguration().setEnvironment(nonSpring);
JtaTransactionManager jtaManager = new JtaTransactionManager(new MockUserTransaction());
DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
txDef.setPropagationBehaviorName("PROPAGATION_REQUIRED");
TransactionStatus status = jtaManager.getTransaction(txDef);
try {
session = SqlSessionUtils.getSqlSession(sqlSessionFactory);
session.getMapper(TestMapper.class).findTest();
// Spring is not managing SqlSession, so commit is needed
session.commit(true);
SqlSessionUtils.closeSqlSession(session, sqlSessionFactory);
jtaManager.commit(status);
// assume a real JTA tx would enlist and commit the JDBC connection
assertNoCommitJdbc();
assertCommitSession();
MockConnection mockConnection = (MockConnection) mockDataSource.getConnection();
assertEquals("should call commit on Connection", 0, mockConnection.getNumberCommits());
assertEquals("should not call rollback on Connection", 0, mockConnection.getNumberRollbacks());
assertEquals("should not call DataSource.getConnection()", 0, dataSource.getConnectionCount());