我想在其标签集中找到包含所有给定标签的项目。
以下是简化的类:
@Entity
class Item {
@ManyToMany
var tags: java.util.Set[Tag] = new java.util.HashSet[Tag]()
}
@Entity
class Tag {
@ManyToMany(mappedBy="tags")
var items: java.util.Set[Item] = new java.util.HashSet[Item]
}
如果我这样尝试
select distinct i
from Item i join i.tags t
where t in (:tags)
我得到包含任何给定标签的项目。这并不奇怪,但我想要包含所有给定标签的项目。所以我反过来尝试:
select distinct i
from Item i join i.tags t
where (:tags) in t
我收到错误消息org.hibernate.exception.SQLGrammarException: arguments of row IN must all be row expressions
。如果tags
只包含一个标签,它就可以工作,但它会失败并不止于此。
如何在 JPQL 中表达这一点?