How can I validate that all JDBC access happens on an active transaction, i.e. java.sql.Connection.getAutoCommit() always return false?
I'm using Spring for transaction management ( @Transactional ) and Hibernate for data access.
Update: What happens is that some Hibernate access is performed without the service method being annotated with @Transactional. That's what I want to be notified of.
Update 2: Code sample
It's possible to call the following code:
public ServiceImpl implements Service {
// missing @Transactional
public List<String> getSomeIds() {
return getDao().getSomeIds();
}
}
Use PROPAGATION_REQUIRED on all persistent methods.
One way I can think of is to implement and register a dummy JDBC Driver to act as an interceptor between the statements you want to monitor as well as keep a log of when Connection#setAutoCommit() and Connection#commit() is called to know the boundaries of the transaction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With