简体   繁体   中英

Query @ElementCollection in an @Entity with a Collection

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"?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM