Reputation: 171
I am working on a spring-boot project.
Before using @Transactional
annotation in my project I have two questions
Best practice to use @Transactional
annotation in spring-boot, service layer or DAO layer?
If the service layer then where do I use the @Transactional
annotation on a class or on a method in that class?
Upvotes: 7
Views: 4956
Reputation: 58774
Service layer may call different DAO to perform DB operations. Lets assume a situations where you have 3 DAO operations in a service method. If your 1st DAO operation failed, other two may be still passed and you will end up inconsistent DB state. Annotating Service layer can save you from such situations.
At the class level, this annotation applies as a default to all methods of the declaring class and its subclasses
Upvotes: 4
Reputation: 691635
Upvotes: 4