Home » Java » java – Propagation.NEVER vs No Transaction vs Propagation.Required-Exceptionshub

java – Propagation.NEVER vs No Transaction vs Propagation.Required-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment


I have an integration test where I’m trying to understand the difference in behavior for different propagation types (required and never) vs no transaction at all. Here’s my integration test:

@Transactional(propagation = Propagation.REQUIRED, transactionManager="transactionManager")
public class MyRepositoryTest {

    private MyRepository myRepo;

    public void test() throws SQLException {
        myRepo.getSession("user", "password");


My repo is:

public interface MyRepository extends Repository<String, String> {

    String getSession(String loginName, String password);

    Blob getDataUsingId(int id);


If I use Propagation.REQUIRED as shown in the test code above, the program hangs when calling getDataUsingId. This is because that stored procedure

  1. Inserts a row
  2. Calls an external service
  3. Waits for that external service to insert a row

It hangs b/c the external service reads the insert (which must be committed) from step 1 before it can insert its row.

If I use no transaction (i.e. remove the @Transactional line), I get an error when calling getDataUsingId. The error complains about an invalid TDS stream. (I’m using the MS SQL Server driver.) This is because the number of bytes are greater than 8000.

If I use Propagation.NEVER, it works. But why?


If set PacketSize=0 in the JDBCURL, it also works when in the case that I have no transaction.

How to&Answers: