我有这些课程:
class Category {
Set usersLinked
def hasMany = [usersLinked:CategoryUserLink]
static namedQueries = {
getAuthorizedBusiness { auser ->
eq "business", true
usersLinked{
eq "user", auser
type{
eq "name", "Authorized"
}
}
}
}
}
class CategoryUserLink {
User user
CategoryType type
Category category
}
当我使用namedQuery
或createCriteria
查询时,我收到错误消息:
Category.getAuthorizedBusiness(user).list()
没有这样的属性usersLinked
为什么呢?
我收到此错误消息:
org.hibernate.QueryException: could not resolve property: userslinked of: lli.faqapp.domain.Category
at grails.orm.HibernateCriteriaBuilder.invokeMethod(HibernateCriteriaBuilder.java:1223)
at grails.orm.GormLabsHibernateCriteriaBuilder.super$3$invokeMethod(GormLabsHibernateCriteriaBuilder.groovy)
at grails.orm.GormLabsHibernateCriteriaBuilder.methodMissing(GormLabsHibernateCriteriaBuilder.groovy:65)
at lli.faqapp.domain.Category$__clinit__closure3_closure4.doCall(Category.groovy:84)
at grails.orm.HibernateCriteriaBuilder.invokeClosureNode(HibernateCriteriaBuilder.java:1367)
at grails.orm.HibernateCriteriaBuilder.invokeMethod(HibernateCriteriaBuilder.java:1117)
at GormLabsGrailsPlugin$_registerCriteria_closure23_closure38.doCall(GormLabsGrailsPlugin.groovy:255)
at lli.faqapp.domain.tests.CategoryTests.testSearchOnCategories(CategoryTests.groovy:39)
删除插件GormLabs
后,我开始进行集成测试,收到此消息:
org.hibernate.QueryException: could not resolve property: userslinked of: lli.faqapp.domain.Category
at grails.orm.HibernateCriteriaBuilder.invokeMethod(HibernateCriteriaBuilder.java:1223)
at lli.faqapp.domain.Category$__clinit__closure3_closure4.doCall(Category.groovy:84)
at grails.orm.HibernateCriteriaBuilder.invokeClosureNode(HibernateCriteriaBuilder.java:1367)
at grails.orm.HibernateCriteriaBuilder.invokeMethod(HibernateCriteriaBuilder.java:1117)
at lli.faqapp.domain.tests.CategoryTests.testSearchOnCategories(CategoryTests.groovy:39)
答案 0 :(得分:2)
hasMany
必须是静态的 - 它是Class的属性,而不是特定的实例。它生成的Set usersLinked
是特定于实例的,但hasMany
声明适用于Class。