Query @ElementCollection in an @Entity with a Collection

你离开我真会死。 提交于 2019-12-12 04:18:07

问题


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();
}

How can I query it to find all Entries where users is "John" and groups are "Foo", "Bar" and "FooBar"?


回答1:


Try using something like this

@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);


来源:https://stackoverflow.com/questions/34121907/query-elementcollection-in-an-entity-with-a-collection

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!