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:
- Is it possible to invoke transactional method from non transactional method in Spring?
- Spring @Transaction method call by the method within the same class, does not work?
- etc...
Any suggestions and ideas?