Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dontRollbackOn parameter of @Transactional annotation is ignored #465

Closed
michalpetrov opened this issue Mar 27, 2020 · 1 comment
Closed
Labels
type: bug Something isn't working
Milestone

Comments

@michalpetrov
Copy link

Transactional manager doesn't commit the transaction after throwing exception which is set in @Transactional annotation as dontRollbackOn.

This should be still commited to db:

    @Transactional(dontRollbackOn = NoRollbackException.class)
    public void updateToFail(Long id) throws NoRollbackException {
        repository.update(id, FAIL);
        throw new NoRollbackException();
    }

From logs:

13:40:25.234 [main] DEBUG io.micronaut.data.query - Executing Query: UPDATE `SIGNATURE` SET `STATE`=? WHERE (`ID` = ?)
13:40:25.235 [main] DEBUG i.m.t.j.DataSourceTransactionManager - Initiating transaction rollback
13:40:25.235 [main] DEBUG i.m.t.j.DataSourceTransactionManager - Rolling back JDBC transaction on Connection [ProxyConnection[PooledConnection[conn9: url=jdbc:h2:mem:devDb user=SA]]]
13:40:25.236 [main] DEBUG i.m.t.j.DataSourceTransactionManager - Releasing JDBC Connection [ProxyConnection[PooledConnection[conn9: url=jdbc:h2:mem:devDb user=SA]]] after transaction

Project to reproduce: https://github.com/michalpetrov/mn-jdbc-rollback-bug

Any workaround will be appreciated.

@graemerocher graemerocher added the type: bug Something isn't working label Mar 27, 2020
@graemerocher graemerocher added this to the 1.0.2 milestone Mar 27, 2020
@michalpetrov
Copy link
Author

After further investigation it seems to be combination of two bugs.

First, I tried to use @TransactionalAdvice instedaof @Transactional but it didn't help. After debuging I found that the problem is with this condition:

return noRollbackFor.stream().anyMatch(t -> t.isInstance(ex));

should be changed to:

return noRollbackFor.stream().noneMatch(t -> t.isInstance(ex));

after this fix it's working correctly with @TransactionalAdvice but still not working with @Transactional

Second problem is with the mapper from @Transactional to @TransactionalAdvice:

annotation.get("dontRollbackOn", String[].class).ifPresent(type ->

but rollbackOn and dontRollbackOn are classes a not strings, so it should be changed to:

annotation.get("dontRollbackOn", AnnotationClassValue[].class).ifPresent(type ->

Would submit a PR but I have no idea how to write tests for annotations processors. So hope this helps too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants