I'm stuck with the following hypothetical problem:
Using the Criteria API (and not JPQL), and given
A table full of users, each one having multiple cars
@Entity public class User { @Id private Long id; @OneToMany private Set<Car> cars; }
@Entity public class Car { @Id private Long id; private String model; }
A
Set<String>
containing car models:Set<String> models = getThousandsOfModels();
How can I select the
User
s having at least oneCar
whosemodel
is in themodels
Set ?
I've read many SO answers, tried different ways (the most promising seemed to involve creating predicates with Expression<Collection<String>>
, using .in()
etc.) but nothing worked.