我有三个域名(DC),名为One,Two&三。
(DC)一个和三个被保留到MongoDB,而(DC)两个是嵌入的类到一级。
(第二类不会持久存在MongoDB。)
代码:
//One.groovy
class One {
ObjectId id
List<Two> two
static hasMany = [two: Two]
static embedded = ['two']
static constraints = {
two nullable: true
}
}
-------------
//Two.groovy
class Two {
Three three
static mapWith = "none"
static constraints = {
three nullable: true
}
}
----------
//Three.groovy
class Three {
ObjectId id
String ...
// some attributes later..
static hasMany = [....]
static mappedBy = [...]
static embedded = [...]
}
我面临的问题是,当我保存Class One的对象时,第二类中的所有对象(如第三类)都在mongoDB中更新。
证明:(MongoDB日志)
2015-07-11T02:32:01.299+0530 [conn113] update database.three query: {
....many such lines means these are getting updated.
如何防止此级联保存。
配置:
grails 2.4.3
mongodb 2.6.4
插件:
compile ":mongodb:3.0.3"
compile ":spring-security-core:2.0-RC5"
注意:不使用任何Hibernate插件
更新:尝试删除
static hasMany = [two: Two]
从Class One我仍然看到在MongoDB中更新了三个日志