I have a User entity with skills property as a type List. I want to query the User table against a list of skills in such a way that if all the skills are present in skill column then only a match is found unless no.
I have used JPQL for this but it matches each element in the list one by one using the IN clause.
User Class
@Entity(name = "App_User")
//table name "user" is not allowed in postgres
public class User {
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
@Column(name = "user_id", updatable = false, nullable = false)
@Setter(AccessLevel.NONE)
private UUID id;
@Column(name = "user_name")
@NotBlank(message = "Name is mandatory")
private String name;
@Column(name = "user_email")
@NotBlank(message = "Email is mandatory")
private String email;
// Current point balance of the user
@Column(name = "points")
private int points;
@ElementCollection(fetch = FetchType.EAGER)
@Column(name = "skills")
@NotEmpty
private List<String> skills = new ArrayList();
}
JPA query that I have used is
SELECT u FROM App_User u JOIN u.skills skill where skill in :skillList
If I want to match a list of skills like this Arrays.asList("skill1","skill2","skill3")then I want only those users in the result who have all of these skills, not one or two. Above used IN clause return the same result.
I have read that it is not possible to compare two lists in JPQL so how can I achieve this using CriteriaBuilder CriteriaQueryAPI?