If you want your service as transactional, set true for the transaction property (this is not necessary, but if you want to clearly indicate that the service is transactional):
class MyService { static transactional = true def method1() { } def method2() { } }
If you do not want:
class MyService { static transactional = false @Transactional(...config...) def method1() { } def method2() { } }
Another example (setting a transaction property is optional, but helps to be clear - if you're not the only encoding):
import org.springframework.transaction.annotation.Transactional class BookService { @Transactional(readOnly = true) def listBooks() { Book.list() } @Transactional def updateBook() {
Another thing you can do is annotate the whole class and override the methods you need to be different:
import org.springframework.transaction.annotation.Transactional @Transactional class BookService { @Transactional(readOnly = true) def listBooks() { Book.list() } def updateBook() {
Hope this helps;)
source share