Grails:namedQuery 错误:重复的关联路径
Grails 1.3.7
当我尝试调用命名查询时,出现了这个奇怪的错误。它的定义如下;
containsQuery { query ->
or{
ilike("name", '%' + query + '%')
ilike("description", '%' + query + '%')
tokens{
ilike("token", '%' + query + '%')
}
}
我得到的错误是:
Error 500: Executing action [list] of controller [net.turkino.tokenadmin.reg.ItemController] caused exception: duplicate association path: tokens
Servlet: grails
URI: /grails/item/list.dispatch
Exception Message: duplicate association path: tokens
Caused by: duplicate association path: tokens
Class: ItemController
At Line: [75]
第 75 行是:
items = itemQueryResult.listDistinct(params)
其中 itemQueryResult 是
itemQueryResult = Item.belongsToOwner(SecurityUtils.subject.principal).containsQuery(params.q)
什么问题?我是否不允许在 nameQuery 中使用令牌?
更新:有关涉及的域类的信息:
class Item{
... // a lot of fields
static hasMany = [ tokens:TokenTag]
static belongsTo = [owner: User]
static mappedBy = [ tokens: 'item' ]
static mapping = { tokens lazy:false }
... // constraints to fields, named queries etc.
static namedQueries = {
belongsToOwner { email ->
owner{
eq("email", email)
}
}
....
}
}
class TokenTag{
... // fields
String token
String tokenAsQRString
Item item
... // other fields
static belongsTo = [tagSheet:TokenTagSheet]
...
}
Grails 1.3.7
I get this strange error when I try to invoke my named query. It is defined as follows;
containsQuery { query ->
or{
ilike("name", '%' + query + '%')
ilike("description", '%' + query + '%')
tokens{
ilike("token", '%' + query + '%')
}
}
the error I get is:
Error 500: Executing action [list] of controller [net.turkino.tokenadmin.reg.ItemController] caused exception: duplicate association path: tokens
Servlet: grails
URI: /grails/item/list.dispatch
Exception Message: duplicate association path: tokens
Caused by: duplicate association path: tokens
Class: ItemController
At Line: [75]
and 75th line is:
items = itemQueryResult.listDistinct(params)
where itemQueryResult is
itemQueryResult = Item.belongsToOwner(SecurityUtils.subject.principal).containsQuery(params.q)
what is the problem? Am I not allowed to use tokens in my namedQuery ?
UPDATE: info about domain classes involved:
class Item{
... // a lot of fields
static hasMany = [ tokens:TokenTag]
static belongsTo = [owner: User]
static mappedBy = [ tokens: 'item' ]
static mapping = { tokens lazy:false }
... // constraints to fields, named queries etc.
static namedQueries = {
belongsToOwner { email ->
owner{
eq("email", email)
}
}
....
}
}
class TokenTag{
... // fields
String token
String tokenAsQRString
Item item
... // other fields
static belongsTo = [tagSheet:TokenTagSheet]
...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了 JIRA 问题 http://jira.grails.org/browse/GRAILS-7324 这可以解释这种行为。这个问题在 2.0-M2 中得到了修复。可能您在“params”中有一个排序参数“tokens”或“tokens.token”。
您可以删除排序参数并查看它是否可以解决您的问题。如果您绝对需要按“令牌”排序,请考虑升级 Grails 版本或使用上述问题中的修复程序修补当前版本。
I located a JIRA issue http://jira.grails.org/browse/GRAILS-7324 which might explain this behavior. This was fixed in 2.0-M2. Possibly you have a sort parameter 'tokens' or 'tokens.token' in 'params'.
You could possibly remove the sort parameter and see if it resolves your issue. If you absolutely need to sort by 'tokens', consider upgrading the Grails version or patch up the current version with the fix in the above issue.