Figured out from here:
https://stackoverflow.com/a/58831350/10894456
@Transactional doesn't lock rows triggered on entities which are used inside @Transactional methods.
And one need to use either optimistic ( @Version annotation in Entities) or pessimistic ( @Lock in repositary methods) explicit directives out of the @Transactional method.
The question is: how does isolation work on @Transactional methods in the face of any locks absence?
e.g.
@Service
public class AService {
@Autowired
private Repository1 repository1;
@Autowired
private Repository2 repository2;
@Autowired
private Repository3 repository3;
@Transactional(isolation = Isolation.SERIALIZABLE)
public Result getResult(Long id) {
Entity1 e1 = repository1.findById(id);
Entity2 e2 = repository2.findById(id);
Entity3 e3 = repository3.findById(id);
e1.setField(doSomeLogic(...)));
e2.setField(doSomeLogic(...)));
e3.setField(doSomeLogic(...)));
repository1.save(e1);
repository2.save(e2);
repository3.save(e3);
return Result.combine(e1,e2,e3);
}
}
What is guaranteed by using
@Transactional(isolation = Isolation.SERIALIZABLE)
? And how do this guarantees work without any locking?