【问题标题】:Selecting where an entity contains a list which elements are not in another list选择一个实体在哪里包含一个列表,哪些元素不在另一个列表中
【发布时间】:2013-02-08 20:40:19
【问题描述】:

我的问题是基于另一个问题:Selecting where an entity contains a list thats a subset of another list

但我想做的是:

我正在编写一个 JPQL 查询并且我有以下场景。我有一个包含标签列表的问题实体。我想选择列表中不包含任何给定标签的所有问题。我如何使用 JPA 做到这一点?

我想做一些类似 SELECT x FROM Question x WHERE x.tags 'do not contains any' :tags 的事情

我尝试使用“NOT IN”,但它不起作用。在这种情况下,它至少返回一个不在“标签”列表中的标签的所有问题。我只想返回所有标签不在“标签”列表中的问题。

有什么建议吗?

【问题讨论】:

    标签: jpa jpql


    【解决方案1】:

    尝试在列表中查找具有项目的员工的子选择,然后在主查询中使用不存在。类似的东西

    SELECT x FROM Question x WHERE not exists( select tag from x.tags tag where tag in  :tags )
    

    【讨论】:

      猜你喜欢
      • 2011-06-06
      • 2018-12-28
      • 1970-01-01
      • 2023-01-22
      • 1970-01-01
      • 2012-08-01
      • 2018-04-19
      • 1970-01-01
      • 2011-03-30
      相关资源
      最近更新 更多