简体   繁体   中英

Grails domain associations with cascading save enabled and transactions

Say we have the following two domain classes:

class Book {
    static belongsTo = [author: Author]
}
class Author {
    static hasMany = [books: Book]
}

No if an Author is initialized with several books and Author.save() is called then the save cascades to Book and both Author and Book instances are saved into db.

However I can't find anywhere in documentation if the mentioned operation will be done transactionally or not.

Any idea?
Any resource to check ?

The answer depends on where the save is done . Is it done in a controller action marked as transactional? Is it in a service which uses transactions by default? Or is it done somewhere else where there is no transaction.

If the save is done somewhere that supports transaction (two examples above) then yes, it will be. Otherwise, no it won't be.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM