Grails hasMany:当子版本更新时,父版本会更改
我正在使用 Grails,并且对 hasMany
关系的工作方式感到非常惊讶。我有一个典型的 hasMany
关系,其中父 ID 位于子表中。当我插入一个子对象并尝试通过父对象保存它时,父对象的版本 ID 会增加。我的问题是:当仅子对象发生更改时,为什么父对象的版本 ID 应该更改?
class Parent {
static hasMany = [children: child]
}
class child {
string name
Parent parent
static belongsTo = [Parent]
}
def p = Parent.get(1)
p.addToChildren(new Child(name: "Roy"))
p.save()
p
的版本从 0 增加到 1。在 Grails 中有什么方法可以避免这种情况吗?
由于父版本 ID 的更改,我收到了陈旧对象异常。有什么帮助吗?
I am using Grails and am quite surprised by the way hasMany
relationships work. I have a typical hasMany
relationship where the parent id is in the child table. When I insert a child and try to save it through the parent object, the parent object's version id gets incremented. My question is: Why should the parent's version id change when there is a change only in the child object?
class Parent {
static hasMany = [children: child]
}
class child {
string name
Parent parent
static belongsTo = [Parent]
}
def p = Parent.get(1)
p.addToChildren(new Child(name: "Roy"))
p.save()
The version of p
gets incremented from 0 to 1. Is there any way I can avoid this in Grails?
Due to the change in version ID of the parent I get a stale object exception. Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种可能性是 为您的域对象禁用乐观锁定。
更新
或尝试搜索。
One possibility is to disable optimistic locking for your domain object.
Update
Or try to search.