I want to find the items that contain all the given tags in their tags set.
Here are the simplified classes:
@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]
}
If I try it like this
select distinct i
from Item i join i.tags t
where t in (:tags)
I get the items that contain any of the given tags. That is not surprising, but I want Items that contain all of the given tags. So I try it the other way around:
select distinct i
from Item i join i.tags t
where (:tags) in t
I get the error message org.hibernate.exception.SQLGrammarException: arguments of row IN must all be row expressions
. It works if tags
contains only a single tag, but it fails with more than that.
How can I express this in JPQL?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…