Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use @Transactional annotation in Spring boot

I am working on a spring-boot project.

Before using @Transactional annotation in my project I have two questions

  1. Best practice to use @Transactional annotation in spring-boot, service layer or DAO layer?

  2. If the service layer then where do I use the @Transactional annotation on a class or on a method in that class?

like image 834
Shaha Nawaj Mulla Avatar asked May 02 '19 06:05

Shaha Nawaj Mulla


1 Answers

  1. in the service layer: you want your whole business method to be ACID
  2. on the class if you want all bean methods to be transactional, on the method if you want that specific method to be transational, or to have different transactional attributes
like image 73
JB Nizet Avatar answered Sep 21 '22 17:09

JB Nizet