Search in sources :

Example 1 with JpaCriteriaBuilder

use of org.eclipse.persistence.jpa.JpaCriteriaBuilder in project eclipselink by eclipse-ee4j.

the class AdvancedCriteriaQueryTestSuite method testFromToExpression.

public void testFromToExpression() {
    EntityManager em = createEntityManager();
    beginTransaction(em);
    try {
        JpaCriteriaBuilder cb = (JpaCriteriaBuilder) em.getCriteriaBuilder();
        CriteriaQuery<Employee> cquery = cb.createQuery(Employee.class);
        Root<Employee> emp = cquery.from(Employee.class);
        cquery.where(cb.fromExpression(cb.toExpression(emp).get("id").notNull()));
        TypedQuery<Employee> tquery = em.createQuery(cquery);
        List<Employee> result = tquery.getResultList();
        result.size();
    } finally {
        rollbackTransaction(em);
        closeEntityManager(em);
    }
}
Also used : EntityManager(jakarta.persistence.EntityManager) Employee(org.eclipse.persistence.testing.models.jpa.advanced.Employee) JpaCriteriaBuilder(org.eclipse.persistence.jpa.JpaCriteriaBuilder)

Aggregations

EntityManager (jakarta.persistence.EntityManager)1 JpaCriteriaBuilder (org.eclipse.persistence.jpa.JpaCriteriaBuilder)1 Employee (org.eclipse.persistence.testing.models.jpa.advanced.Employee)1