Grails:namedQuery 错误:重复的关联路径

发布于 2025-01-01 12:53:54 字数 1474 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

打小就很酷 2025-01-08 12:53:54

我找到了 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文