Question ID 4604 | The developer wants to write a criteria query that will return the number of orders made by customer of each county.
Assume that customer is an entity with a unidirectional one-to-many relationship to the Order entity and that Address is an embeddable class, with an attribute country of type String.
Which one of the queries below correctly achieves this?
|
Option A | A. CriteriaBuilder cb> = ...
CriteriaQuery cq = cb.createQuery();
Root<Customer> c = cq.from(Customer.class);
Join<Customer, Order> o = c.join(Customer_.orders);
cq.multiselect(cb.count(0), c,get(customer_.address.get(address_.country) cq.groupBy (c.get(customer_.address) .get(address_.country))
|
Option B | B. CriteriaBuilder cb> = ...
CriteriaQuery cq = cb.createQuery();
Root<Customer> c = cq.from(Customer.class); cq.select (cb.count(c.join
(customer_. Orders)) , c.get(customers(0), c.get(customer_.address) . get (Address_’country));
(c.get(Customer_.address). get(address_.country));
|
Option C | C. CriteriaBuilder cb> = ...
CriteriaQuery cq = cb.createQuery();
Root<Custower> c = cq.from(Customer.class);
Join<Customer, Order> o = c.join(Customer_.orders);
cq.select(cb.count(o));
cq.groupBy(c.qet(Customer__.address) - get(Address_.country)) ;
|
Option D | D. CriteriaBuilder cb = ...
CriteriaQuery cq = cb.createQueryO;
Root<Customer> c = cq.from(Customer.class);
Join<Customer, Order> o = c.join(Customer_.orders);
Join<Address, String> country = c.join(Customer,.address) .join(Address
cq.multiselect(cq.count(o), country );
cq.groupBy(c.get(Customer.address) - get (Address_ . country) ) ;
|
Correct Answer | A |
Question ID 4605 | The developer wants to write a portable criteria query that will order the orders made by customer James Brown according to increasing quantity. Which one of the below queries correctly accomplishes that task?
|
Option A | A. CriteriaBuilder cb= . . .
CriteriaQuery<order> cq = cb.createquery<order.class> Root <customer, order>c= cq.from(customer.class); Join <customer, order>o= c.Join(customer_.orders); cq.where (cb.equal(c.get(customer_.name, James Brown)));
cq.orderBy (o.get (order_.quantity));
|
Option B | B.
CriteriaBuilder cb= . . .
CriteriaQuery<order> cq = cb.createquery<order.class>
Root <customer, order>c= cq.from(customer.class);
Join <customer, order>o= c.Join(customer_.orders);
cq.where (cb.equal(c.get(customer_.name, James Brown))); cq.select(o);
cq.orderBy (o.get (order_.quantity));
|
Option C | C. CriteriaBuilder cb= . . .
CriteriaQuery<order> cq = cb.createquery<order.class> Root <customer, order>c= cq.from(customer.class); Join <customer, order>o= c.Join(customer_.orders); cq.where (cb.equal(c.get(customer_.name, James Brown)));
cq.orderBy (o.get (order_.quantity));
cq.select(o);
|
Option D | D. CriteriaBuilder cb= . . .
CriteriaQuery<order> cq = cb.createquery<order.class> Root <customer, order>c= cq.from(customer.class); Join <customer, order>o= c.Join(customer_.orders); cq.where (cb.equal(c.get(customer_.name, James Brown)));
cq.orderBy (o.get (order_.quantity));
cq.orderBy (“quantity”);
|
Correct Answer | B |