Verify that all JDBC calls occur in a transaction

How can I verify that all JDBC access occurs with an active transaction, i.e. java.sql.Connection.getAutoCommit()always returns false?

I use Spring for transaction management ( @Transactional) and Hibernate for data access.


Update. What happens is that some access to Hibernate is done without annotating the service method with @Transactional. This is what I want to be notified about.

Update 2: Sample Code

You can call the following code:

public ServiceImpl implements Service {

     // missing @Transactional
     public List<String> getSomeIds() {
           return getDao().getSomeIds();
     }
}
+3
source share
3 answers

Use PROPAGATION_REQUIRED for all persistent methods.

+2

, , - JDBC-, , , , Connection # setAutoCommit() Connection # commit() .

+2

, @Transactional documentation, 9.5.6.1:

@Transactional :

 The propagation setting is PROPAGATION_REQUIRED
 ....

PROPAGATION_REQUIRED :

, , .

: , @duffymo :

, DAO , .

+1

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


All Articles