I was studying a bit about the @Transactional annotation (Spring version), and I had a question. According to a publication made in DevMedia , the way more correct "to use is noting in our business method, because there can have several actions in the bank, not one in specific. So I thought to myself, if in my RestFull application, it would not be more feasible to jot down the endpoint (which only calls a method) to make a transaction of everything from that point forward. Example:
@PostMapping
@Transactional(propagation = Propagation.REQUIRED)
public Response< ? > criarNovaViagem(@RequestBody ViagemRequest novaViagem) throws ViagemServiceApplicationException {
return new Response<>(true, this.viagemService.criarViagem(novaViagem), null);
}
This method " criarNovaViagem()
" does N operations in N different tables. Is it wrong or "pig" I annotate my endpoint with @Transacional
?