一个额外的属性使Grails将关系解释为双向多对一

一个额外的属性使Grails将关系解释为双向多对一,grails,gorm,Grails,Gorm,我真正的课程是不同的,所以请容忍我这个例子的有限意义。 假设我有两个类:树和工具。树有许多经过授权的工具。但其中一个工具是连接两棵树的Rope,因此Rope扩展了该工具,并具有一个属性endTree来存储另一棵树: class Tree { static hasMany = [tools: Tool] } class Tool { // it doesn't matter here what the tool can do } class Rope extends Tool

我真正的课程是不同的,所以请容忍我这个例子的有限意义。 假设我有两个类:树和工具。树有许多经过授权的工具。但其中一个工具是连接两棵树的Rope,因此Rope扩展了该工具,并具有一个属性endTree来存储另一棵树:

class Tree { 
    static hasMany = [tools: Tool]
}

class Tool {
    // it doesn't matter here what the tool can do
}

class Rope extends Tool {
    Tree endTree
}
我遇到的问题是Grails认为这种关系是双向的,因此在对实体求值期间,AbstractGrailDomainBinder中的isBidirectionalManyToOneWithListMapping()返回true,实际上是将endTree属性设置为updateable=false,hibernate在保存和更新期间跳过endTree

我做错了什么

谢谢


Mb

通过使用
mappedBy
值“none”,可以明确告诉Grails不要将属性视为双向关系的一方:

和/或绳子上的相同部分端部:

class Rope extends Tool {
    Tree endTree
    static mappedBy = [endTree: "none"]
}

我不确定您是否需要两端的
mappedBy
,或者其中一个是否足够。

我只将此mappedBy放在树中,效果很好。谢谢
class Rope extends Tool {
    Tree endTree
    static mappedBy = [endTree: "none"]
}