Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does @Transactional annotation work if autocommit is true?

Would roll back work if auto commit is turned on? if not then what is the implications of turning auto commit off?

@Transactional(rollbackFor = {ManagerException.class})
public myMethod()....{
    System.out.printLn(my_spring_stored_procedure.getDataSource()
            .getConnection().getAutoCommit()) //true
    ....
    try {
        result = this.my_spring_stored_procedure.execute(params);
    }catch(DataAccessException e){
        throw new ManagerException(e);
    }
}
like image 400
code511788465541441 Avatar asked Mar 18 '13 12:03

code511788465541441


People also ask

Does @transactional work on protected methods?

As most of you probably know, due to the very nature of the solution, Spring's @Transactional annotation does not work on private methods unless you're using the AspectJ mode (which, in my experience, most of us aren't).

What does the @transactional annotation do?

Transactional annotation provides the application the ability to declaratively control transaction boundaries on CDI managed beans, as well as classes defined as managed beans by the Java EE specification, at both the class and method level where method level annotations override those at the class level.

On which can the @transactional annotation be applied?

The @Transactional annotation is the metadata that specifies the semantics of the transactions on a method. We have two ways to rollback a transaction: declarative and programmatic. In the declarative approach, we annotate the methods with the @Transactional annotation.

How does Spring @transactional really work?

So when you annotate a method with @Transactional , Spring dynamically creates a proxy that implements the same interface(s) as the class you're annotating. And when clients make calls into your object, the calls are intercepted and the behaviors injected via the proxy mechanism.


1 Answers

Yes. If you check the code, you will find that when the spring uses this kind of way to do the transaction. If your config is that auto commit is true, then it will change it to false and after the transaction it will change it to true.

like image 103
OQJF Avatar answered Sep 22 '22 13:09

OQJF