psorobka
psorobka

Reputation: 11

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

Upvotes: 0

Views: 2027

Answers (1)

Robert Niestroj
Robert Niestroj

Reputation: 16131

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

Upvotes: 1

Related Questions