在具有集合的@Entity中查询@ElementCollection [英] Query @ElementCollection in an @Entity with a Collection
本文介绍了在具有集合的@Entity中查询@ElementCollection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个@Entity(JPA 2.0)
Let's say that I have an @Entity (JPA 2.0)
@Entity
class Entry {
@ElementCollection
Set<String> users = new HashSet();
@ElementCollection
Set<String> groups = new HashSet();
}
如何查询它以查找用户为"John"且组为"Foo","Bar"和"FooBar"的所有条目?
How can I query it to find all Entries where users is "John" and groups are "Foo", "Bar" and "FooBar"?
推荐答案
尝试使用类似的方法
@Query("SELECT DISTINCT e FROM Entry e WHERE :user MEMBER OF e.users AND :groups in e.groups")
List<Entry> yourQuery(@Param("user") String user, @Param("groups") List<String> groups);
这篇关于在具有集合的@Entity中查询@ElementCollection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文