Search in sources :

Example 96 with CriteriaQuery

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();
        }
    }
}
Also used : CriteriaBuilder(jakarta.persistence.criteria.CriteriaBuilder) EntityManager(jakarta.persistence.EntityManager) TypedQuery(jakarta.persistence.TypedQuery) Query(jakarta.persistence.Query) CriteriaQuery(jakarta.persistence.criteria.CriteriaQuery) L1(org.eclipse.persistence.jpa.test.criteria.model.L1) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

CriteriaQuery (jakarta.persistence.criteria.CriteriaQuery)96 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)82 EntityManager (jakarta.persistence.EntityManager)64 Query (jakarta.persistence.Query)63 List (java.util.List)54 TypedQuery (jakarta.persistence.TypedQuery)35 Employee (org.eclipse.persistence.testing.models.jpa.advanced.Employee)32 Test (org.junit.jupiter.api.Test)24 JpaQuery (org.eclipse.persistence.jpa.JpaQuery)20 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)16 JpaCriteriaBuilder (org.eclipse.persistence.jpa.JpaCriteriaBuilder)14 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)13 ReportQuery (org.eclipse.persistence.queries.ReportQuery)12 Query (org.hibernate.query.Query)12 QuerySQLTracker (org.eclipse.persistence.testing.framework.QuerySQLTracker)11 BasicEntity (org.hibernate.testing.orm.domain.gambit.BasicEntity)11 Root (jakarta.persistence.criteria.Root)8 HibernateCriteriaBuilder (org.hibernate.query.criteria.HibernateCriteriaBuilder)8 DatabasePlatform (org.eclipse.persistence.platform.database.DatabasePlatform)7