开发者

Grails: Querying Associations causes groovy.lang.MissingMethodException

I've got an issue with Grails where I have a test app with:

class Artist {
static constraints = {
 name()
}

 static hasMany = [albums:Album]
 String name
}

class Album {
 static constraints = {
  nam开发者_如何学编程e()
}

 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
}

The following query (and a more advanced, nested association query) works in the Grails Console but fails with a groovy.lang.MissingMethodException when running the app with 'run-app':

def albumCriteria = tunehub.Album.createCriteria()
def albumResults = albumCriteria.list {
 like("name", receivedAlbum)
 artist { like("name", receivedArtist) } // Fails here
maxResults(1)
}

Stacktrace:

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...)

Any pointers?


what exactly does this constraint mean? Seems suspect to me...

static constraints = {
    name()
}

is what you want?

static constraints = {
    name(nullable:false, blank: false)
}


I often encounter similar problems with Grails. The code is completely as it should be, yet vital GORM methods are mysteriously absent. At the moment, I have a hobby project where DomainClass.list() doesn't work. findAll() should also work, but it doesn't work either. It's a complete mystery. .methods() does include a lot of other methods that Groovy or Grails are supposed to add, but most GORM-specific stuff seems to be missing. Although in the BootStrap, I can create objects of that type and save them to the database.

I don't seem to be having this problem when I create a Grails project at work on my Mac, but it does happen at home on Windows. Weird huh? Is it possible Grails 1.3.6 on Windows is buggy or broken?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜