13.1.1 Transactions and Multi-DataSources 4.0.6

(Quick Reference) # 13.1.1 Transactions and Multi-DataSources Version: 4.0.6 ## 13.1.1 Transactions and Multi-DataSources Given two domain classes such as:
    class Movie {
        String title
    }
    class Book {
        String title

        static mapping = {
            datasource 'books'
        }
    }
You can supply the desired data source to `@Transactional` or `@ReadOnly` annotations.
    import grails.gorm.transactions.ReadOnly
    import grails.gorm.transactions.Transactional
    import groovy.transform.CompileStatic

    @CompileStatic
    class BookService {

        @ReadOnly('books')
        List<Book> findAll() {
            Book.where {}.findAll()
        }

        @Transactional('books')
        Book save(String title) {
            Book book = new Book(title: title)
            book.save()
            book
        }
    }
    @CompileStatic
    class MovieService {

        @ReadOnly
        List<Movie> findAll() {
            Movie.where {}.findAll()
        }
    }
| Quick Reference (hide)