1

Desc

I'm working on the Java Spring project. I've faced the behavior "transaction rollback doesn't work when calling from the same class".

  • My IDE (IDEA) doesn't highlight it.
  • The compiler doesn't throw an exception.
  • The project is very big, and our team is big, and it is very easy to make this mistake.

The question

How to strictly avoid this mistake in a big project?
I wonder - maybe there is an automated solution to not build a project with such mistakes?

Example:

@Service
class MyServiceImpl {
    @Transactional(rollbackFor=Exception.class)
    void method1 () { // direct call works fine.
    }
    void method2 () {
      method1(); // the same class call won't be transactional. Rollback won't work.
    }
}

Manual solutions are already discovered there:

Any suggestions and ideas?

kaluginserg
  • 345
  • 1
  • 4
  • 12

0 Answers0