Hibernate Grails:查询关联导致groovy.lang.MissingMethodException
我对Grails有一个问题,我有一个测试应用程序:Hibernate Grails:查询关联导致groovy.lang.MissingMethodException,hibernate,grails,gorm,Hibernate,Grails,Gorm,我对Grails有一个问题,我有一个测试应用程序: class Artist { static constraints = { name() } static hasMany = [albums:Album] String name } class Album { static constraints = { name() } static hasMany = [ tracks : Track ] static belongsTo = [artist: Artist]
class Artist {
static constraints = {
name()
}
static hasMany = [albums:Album]
String name
}
class Album {
static constraints = {
name()
}
static hasMany = [ tracks : Track ]
static belongsTo = [artist: Artist]
String name
}
class Track {
static constraints = {
name()
lyrics(nullable: true)
}
Lyrics lyrics
static belongsTo = [album: Album]
String name
}
以下查询(以及更高级的嵌套关联查询)在Grails控制台中工作,但在使用“run app”运行应用程序时,由于groovy.lang.MissingMethodException而失败:
def albumCriteria = tunehub.Album.createCriteria()
def albumResults = albumCriteria.list {
like("name", receivedAlbum)
artist { like("name", receivedArtist) } // Fails here
maxResults(1)
}
堆栈跟踪:
groovy.lang.MissingMethodException: No signature of method: java.lang.String.call() is applicable for argument types: (tunehub.LyricsService$_getLyrics_closure1_closure2) values: [tunehub.LyricsService$_getLyrics_closure1_closure2@604106]
Possible solutions: wait(), any(), wait(long), each(groovy.lang.Closure), any(groovy.lang.Closure), trim()
at tunehub.LyricsService$_getLyrics_closure1.doCall(LyricsService.groovy:61)
at tunehub.LyricsService$_getLyrics_closure1.doCall(LyricsService.groovy)
(...truncated...)
有指针吗?这个约束到底意味着什么?在我看来似乎很可疑
static constraints = {
name()
}
这是你想要的吗
static constraints = {
name(nullable:false, blank: false)
}
我经常遇到与Grails类似的问题。代码完全是它应该是的,然而重要的GORM方法却神秘地缺失。目前,我有一个爱好项目,其中DomainClass.list()不起作用。findAll()也应该工作,但它也不工作。这完全是个谜。methods()确实包括Groovy或Grails应该添加的许多其他方法,但大多数GORM特定的东西似乎都缺失了。虽然在引导中,我可以创建这种类型的对象并将它们保存到数据库中
当我在Mac上创建Grails项目时,我似乎没有遇到这个问题,但它确实发生在Windows上的家中。奇怪吧?Windows上的Grails 1.3.6是否可能有缺陷或损坏?能否提供
MissingMethodException
堆栈跟踪?groovy.lang.MissingMethodException:没有方法签名:java.lang.String.call()适用于参数类型:(tunehub.LyricsService$\u GetLyms\u closure1\u closure2)值:[tunehub.LyricsService$\u GetLyps\u closure1_closure2@604106]可能的解决方案:wait()、any()、wait(long)、each(groovy.lang.Closure)、any(groovy.lang.Closure)、trim()在tunehub.LyricsService$\u getlyris\u closure1.doCall(LyricsService.groovy:61)在tunehub.LyricsService$\u getlyris\u closure1.doCall(LyricsService.groovy)(…截断…)我没有发现任何不正确的地方,也许我只是错过了它。你确定这就是错误发生的地方吗?是的-如果我注释掉代码块并使用HQL,它就可以正常工作。更奇怪的是,它在Grails控制台中工作。我使用的唯一非标准功能是PostgreSQL驱动程序…这很奇怪。我恐怕没有任何好的建议每个属性都有一个默认约束。当您在约束块中指定一个没有参数的约束时,它将采用默认值,但脚手架将其用于视图中字段的顺序。它与OPs问题无关。