Consider the following:
@Entity
public class Book
{
private List authors;
@ElementCollection
public List getAuthors
In JPQL:
select b from Book where size(b.authors) >= 2
Using the criteria API (but why would you replace such a simple static query with the following mess?):
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery criteriaQuery = cb.createQuery(Book.class);
Root book = criteriaQuery.from(Book.class);
Predicate predicate = cb.ge(cb.size(book.get(Book_.authors)), 2);
criteriaQuery.where(predicate);
criteriaQuery.select(book);