I have these classes:
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 {
开发者_StackOverflow社区User user
CategoryType type
Category category
}
When I querying on it with a namedQuery
or a createCriteria
I receive an error:
Category.getAuthorizedBusiness(user).list()
No such property usersLinked
Why?
I receive this error message:
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)
And after removing the plugin GormLabs
, I start the integration test and I receive this message:
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)
hasMany
must be static - it's a property of the Class, not a specific instance. The Set usersLinked
that it generates is instance-specific, but the hasMany
declaration is for the Class.
精彩评论