Grails:如何查询域类? hasMany-relationship 反对相交的对象集?

发布于 2024-10-08 07:53:31 字数 342 浏览 0 评论 0原文

我有以下内容:

class Object_1 {
  static hasMany = [tags:Tag]
  Set tags;
  ...
}

现在我有一组标签,并且想要查找具有相交(!=匹配)标签的所有 Object_1 实例。我正在考虑类似的事情

Object_1.findAllByTagsInList(tags);

,但这根本不起作用 - 我得到一个“嵌套异常是 org.hibernate.exception.SQLGrammarException:无法执行查询”。我有一种感觉,我错过了一些重要的事情。非常感谢帮助。

I have about the following:

class Object_1 {
  static hasMany = [tags:Tag]
  Set tags;
  ...
}

Now I have a set of tags and want to find all Object_1-instances with intersecting (!= matching) tags. I was thinking of something like

Object_1.findAllByTagsInList(tags);

But that does not work at all - I get a "nested exception is org.hibernate.exception.SQLGrammarException: could not execute query". I have the feeling I am missing something important. Help highly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

Hello爱情风 2024-10-15 07:53:31

我实际上找到了解决问题的优雅方法。我将关系重新设计为多对多,这样可以简单地迭代标签列表来查找所有相关对象。

...当然现在我必须多次处理这种关系 - 但我很高兴能在很少的地方进行这种工作。

I actually found an elegant way to solve the problem. I redesigned the relationship to be many-to-many which allows for simply iterating over the tags list finding all the relevant objects.

... of course now I have to take care of that relationship a couple of times - but I am happy to have this working with few locs.

﹏雨一样淡蓝的深情 2024-10-15 07:53:31

“in list”不是动态查找方法中识别的运算符之一 - 这是行不通的。

相反,您必须使用 HQL 或条件生成器 来制定您的查询(也许将其放入静态查找方法中)。

"in list" is not one of the operators recognized in dynamic finder methods - that won't work.

Instead, you'll have to use HQL or the criteria builder to formulate your query (and perhaps put it in a static finder method).

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