Does spring commit when it shouldn't be? (related to Oracle autocommit)

I have an interface as shown below

public interface FooDAO {
  public void callA(String x);
}

and the implementation, as shown below, deliberately makes readonly true and is not supported

public class FooDAOImpl implements FooDAO {

  //for testing
  @Transactional(readOnly = true, propagation = Propagation.NOT_SUPPORTED) 
  public void callA(String x) {
     //sql update method
  }
}

In my spring context, I declared a Datasource transaction manager and annotation-driven tx :. I wrote a Junit4 test that looks like

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(...)
@TransactionConfiguration(transactionManager="txManager", defaultRollback=true)
public class MyTest {

    @Resource
    FooDAO fooDAO;

    @Test
    public void testRegisterWorker() {
        fooDAO.callA("")
    }
}

I would expect the record to not be inserted into the database at all. However, I see that the row is being entered into the database. I am using an Oracle database, so I believe that autocommit is set to true by default (I think). But should spring transaction tags not override them?

Can someone tell me what is going wrong here?

+3
3

Autocommit, , . DataSourceTransactionManager autocommit , . NOT_SUPPORTED, SUPPORTS , , , .

Spring xml. , Spring tx , Oracle ( ). .

. org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(), Connection. doBegin() AbstractPlatformTransactionManager.getTransaction() handleExistingTransaction(), , REQUIRES_NEW PROPAGATION_NESTED.


, org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests. Spring, . . , . @Transactional , prod, , , db.

+4

Autocommit - "" JDBC, Oracle ( Oracle DML , , , ).

autocommit . , setAutoCommit.

0

@TransactionConfiguration, @Transactional. DAO, , - propagation = Propagation.NOT_SUPPORTED.

0

Source: https://habr.com/ru/post/1751581/


All Articles