I have a following field in my Entity:
@ElementCollection(targetClass = UserType.class)
@CollectionTable(name = "user_type", joinColumns = @JoinColumn(name = "user_id"))
@Column(name = "ttype", nullable = false)
@Enumerated(EnumType.STRING)
public Set<UserType> getUserTypes() {
return userTypes;
}
public void setUserTypes(Set<UserType> userTypes) {
this.userTypes = userTypes;
}
This fetches collection of user types assigned to particular user. This works fine. Now I need to filter users who are members of { ADMIN, MANAGER } types. So I need to get users who are type of any of type provided in filter.
So I tried
queryRoot.get("userTypes").in(filterTypes)
But this obviously does not work. Seems like CriteriaBuilder provides basic comparison functions like equals
, ge
, etc. But for this check there is nothing.
How to make such query via CriteriaBuilder?