I'm struggling with sonar issue:
squid:S2229 "Methods should not call same-class methods with incompatible "@Transactional" values"
I'm not sure how am I supposed to resolve this. Should I add @Transactional above clean method or something? Or even delete @Transactional annotation.
@Override
public void clean(BooleanSupplier isInterrupted) {
// other code
while (shouldContinue(isInterrupted) && partitionsIterator.hasNext()) {
PartitionDeleteSql partition = partitionsIterator.next();
execute(partition);
}
}
@Transactional
public void execute(PartitionDeleteSql sql) {
// other code
getJdbcTemplate().execute(sql....());
getJdbcTemplate().execute(sql....());
getJdbcTemplate().execute(sql....());
}
The problem that Sonar points as is that the non-transactional method clean calls transactional execute. Therefore the @Transactional annotation on execute is ignored and the method will not get executed in the transactional mode.
You have to annotate either clean method or the whole class with @Transactional.
Also the class itself has to be registered as a Spring bean using for example @Service or @Copmonent, otherwise the proxy wrapper bean will not be created for such class.
Read more at: Spring - @Transactional - What happens in background?
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