启用级联保存和事务的Grails域关联(Grails domain associations with cascading save enabled and transactions)

系统教程 行业动态 更新时间:2024-06-14 16:59:47
启用级联保存和事务的Grails域关联(Grails domain associations with cascading save enabled and transactions)

假设我们有以下两个域类:

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

如果Author用多本书初始化并且Author.save()被调用,那么保存级联到Book并且Author和Book实例都被保存到数据库中, Author.save() 。

但是,如果上述操作将以事务方式进行,我无法在文档中找到任何地方。

任何想法? 任何资源检查?

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.

更多推荐

本文发布于:2023-04-17 09:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/4dcef53fbc742aea8973c92129ff9c04.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:事务   级联   domain   Grails   associations

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!