简体   繁体   English

启用级联保存和事务的Grails域关联

[英]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. 否,如果使用几本书初始化AuthorAuthor.save() ,则将级联保存到Book并将AuthorBook实例都保存到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. 否则,不会的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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