Package javax.persistence.criteria

Examples of javax.persistence.criteria.CriteriaQuery.where()


        Root<Customer> customer = cquery.from(Customer.class);

        //Get Metamodel from Root
        EntityType<Customer> Customer_ = customer.getModel();

        cquery.where(cb.equal(
                customer.get(Customer_.getSingularAttribute("name", String.class)),
                cb.nullLiteral(String.class)));

        Query q = em.createQuery(cquery);
    }
View Full Code Here


        String jpql = "SELECT d FROM Department d LEFT JOIN FETCH d.employees "
                + "WHERE d.deptNo = 1";
        CriteriaQuery q = cb.createQuery();
        Root<Department> d = q.from(Department.class);
        d.fetch(department_.getSet("employees", Employee.class), JoinType.LEFT);
        q.where(
                cb.equal(d.get(department_
                        .getSingularAttribute("deptNo", Integer.class)), 1)).select(d);

        assertEquivalence(q, jpql);
    }
View Full Code Here

        Root<Order> o = q.from(Order.class);
        Join<Order, LineItem> i = o.join(order_.getList("lineItems",
                LineItem.class));
        Join<Order, Customer> c = o.join(order_.getSingularAttribute("customer",
                Customer.class));
        q.where(cb.equal(c.get(customer_.getSingularAttribute("lastName", String.class)), "Smith"),
                cb.equal(c.get(customer_.getSingularAttribute("firstName", String.class)), "John"));
        q.select(cb.sum(i.get(lineItem_.getSingularAttribute("price", Double.class))));

        assertEquivalence(q, jpql);
    }
View Full Code Here

        String jpql = "SELECT SIZE(d.employees) FROM Department d "
         + "WHERE d.name = 'Sales'";
       
        CriteriaQuery q = cb.createQuery();
        Root<Department> d = q.from(Department.class);
        q.where(cb.equal(
                d.get(department_.getSingularAttribute("name", String.class)),
                "Sales"));
        SetAttribute<Department, Employee> employees =
            department_.getDeclaredSet("employees", Employee.class);
        q.select(cb.size(d.get(employees)));
View Full Code Here

        Root<Customer> customer = cquery.from(Customer.class);

        //Get Metamodel from Root
        EntityType<Customer> Customer_ = customer.getModel();

        cquery.where(cb.equal(
                customer.get(Customer_.getSingularAttribute("name", String.class)),
                cb.nullLiteral(String.class)));

        Query q = em.createQuery(cquery);
    }
View Full Code Here

        String jpql = "SELECT d FROM Department d LEFT JOIN FETCH d.employees "
                + "WHERE d.deptNo = 1";
        CriteriaQuery q = cb.createQuery();
        Root<Department> d = q.from(Department.class);
        d.fetch(department_.getSet("employees", Employee.class), JoinType.LEFT);
        q.where(
                cb.equal(d.get(department_
                        .getSingularAttribute("deptNo", Integer.class)), 1)).select(d);

        assertEquivalence(q, jpql);
    }
View Full Code Here

        Root<Order> o = q.from(Order.class);
        Join<Order, LineItem> i = o.join(order_.getList("lineItems",
                LineItem.class));
        Join<Order, Customer> c = o.join(order_.getSingularAttribute("customer",
                Customer.class));
        q.where(cb.equal(c.get(customer_.getSingularAttribute("lastName", String.class)), "Smith"),
                cb.equal(c.get(customer_.getSingularAttribute("firstName", String.class)), "John"));
        q.select(cb.sum(i.get(lineItem_.getSingularAttribute("price", Double.class))));

        assertEquivalence(q, jpql);
    }
View Full Code Here

        String jpql = "SELECT SIZE(d.employees) FROM Department d "
         + "WHERE d.name = 'Sales'";
       
        CriteriaQuery q = cb.createQuery();
        Root<Department> d = q.from(Department.class);
        q.where(cb.equal(
                d.get(department_.getSingularAttribute("name", String.class)),
                "Sales"));
        SetAttribute<Department, Employee> employees =
            department_.getDeclaredSet("employees", Employee.class);
        q.select(cb.size(d.get(employees)));
View Full Code Here

        Root<Customer> customer = cquery.from(Customer.class);

        //Get Metamodel from Root
        EntityType<Customer> Customer_ = customer.getModel();

        cquery.where(cb.equal(
                customer.get(Customer_.getSingularAttribute("name", String.class)),
                cb.nullLiteral(String.class)));

        Query q = em.createQuery(cquery);
    }
View Full Code Here

        cq.select(builder.count(from));

        if (filters != null && !filters.isEmpty()) {
            List<Predicate> predicates = new ArrayList<Predicate>();
            addSimpleFilter (cq, builder, from, filters, predicates);
            cq.where(predicates.toArray(new Predicate[predicates.size()]));
        }

        Query q = getEntityManager().createQuery(cq);
        return ((Long) q.getSingleResult()).intValue();
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.