use of jakarta.persistence.criteria.CriteriaQuery in project eclipselink by eclipse-ee4j.
the class TestCriteriaBuilder method testCriteriaBuilder_IN_ClauseLimit.
@Test
public void testCriteriaBuilder_IN_ClauseLimit() throws Exception {
EntityManager em = emf.createEntityManager();
try {
// "SELECT OBJECT(emp) FROM Employee emp WHERE emp.id IN :result"
final CriteriaBuilder builder = em.getCriteriaBuilder();
final CriteriaQuery<L1> query = builder.createQuery(L1.class);
Root<L1> root = query.from(L1.class);
query.where(root.get("name").in(builder.parameter(List.class, "parameterList")));
Query q = em.createQuery(query);
// Create a list longer than the limit
int limit = getPlatform(emf).getINClauseLimit() + 10;
List<String> parameterList = new ArrayList<String>();
for (int p = 0; p < limit; p++) {
parameterList.add("" + p);
}
q.setParameter("parameterList", parameterList);
q.getResultList();
} finally {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
if (em.isOpen()) {
em.close();
}
}
}
Aggregations