Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Grails 当getter返回同一个类时,自引用有许多次抛出MappingException_Grails - Fatal编程技术网

Grails 当getter返回同一个类时,自引用有许多次抛出MappingException

Grails 当getter返回同一个类时,自引用有许多次抛出MappingException,grails,Grails,我想知道下面的场景是否是Grails bug,或者是否需要一种不同的方式来表示递归关系 使用create app创建Grails 2.1.0应用程序,并使用create domain class创建下面的域类,会在“Grails run app”上产生映射异常: class Person { static hasMany = [neighbours:Person] public Person getBestFriend() { return null }

我想知道下面的场景是否是Grails bug,或者是否需要一种不同的方式来表示递归关系

使用create app创建Grails 2.1.0应用程序,并使用create domain class创建下面的域类,会在“Grails run app”上产生映射异常:

class Person {
    static hasMany = [neighbours:Person]

    public Person getBestFriend() {
        return null
    }
}

Caused by MappingException: Foreign key (FKC4E39B558E488775:person [])) must have same  number of columns as the referenced primary key (person [id])
->> 303 | innerRun in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|   138 | run      in java.util.concurrent.FutureTask
|   886 | runTask  in java.util.concurrent.ThreadPoolExecutor$Worker
|   908 | run      in     ''
^   662 | run . .  in java.lang.Thread
如果getBestFriend的返回类型为Object或任何其他类型,则应用程序将正常启动。改变邻居的人的类型也是如此。加入静态瞬变=['bestFriend']不会产生任何变化


此异常主要出现在使用复合键引用子对象时的搜索中,但我找不到类似于此示例的情况。在此提前感谢您的帮助

我在这里试过,同样的问题也发生了。一个解决方案是使用

如果最好的朋友是个人的财产,这个解决方案就行了。尽管如此,它需要将GORM方法list、get等公开给客户机代码,这对我来说并不是很有趣。但是,如果getBestFriend没有检索到持久化属性,比如简单地返回new Person,我认为命名查询是不够的。为此问题创建了JIRA:
class Person {

    static hasMany = [neighbours:Person]

    //static transients = ['bestFriend']

    //public Person getBestFriend() {
//      return null
//  }

    static namedQueries  = {
        bestFriend {
        }
    }


    static constraints = {

    }
}