简体   繁体   中英

Grails named query

I have two domain classes, Alpha and Beta.

class Beta{
  String betaName
  int age
}

class Alpha{
  String name
  static belongsTo=[creator:Beta]

  static namedQueries = {
    alphaByUser{ param ->
      eq creator.betName,param.betaName
}
    alphaByAge {param -> 
      eq creator.age,param 
    }
  }
}

Now when I call for example Alpha.alphaByUser(betaUser).list() I keep getting things like:

java.lang.NoSuchMethodException: Unknown property 'create' on class 'class org.codehaus.groovy.grails.commons.DefaultGrailsDomainClass'

Or

object is not an instance of declaring class

I just can't seem to get past it...

Any suggestions?

Your criteria syntax is a bit off. Try this:

static namedQueries = {
    alphaByUser{ param ->
        creator {
            eq 'betName', param.betaName
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM