Question ID 4602 | A developer is writing an application with three java Persistence API entities: order, customer, and Address. There is a many-to-one relationship between order and customer, and a one to-many relationship between customer and Address.
Which two Criteria queries will return the orders of all customers who have an address whose value specified by the String parameter postalcode? (Choose two)
|
Option A | A. String postalCode = . . .
Criteria Builder cb = . . .
CriteriaQuery<order> cq = cb.createQuery (Order.class);
Root <order> order = cq.from(order.class);
Join <order, Customer> customer = order.join(Order_.customer);
Root <Order> order = cq.from (Order.class);
Join <customer, Address> address = customer join (Order_.customer)
cq.where (cb.equal (address.get(Address_.postalCode), postalCode));
cq.select (order). Distinct (true);
// query execution code here
. . .
|
Option B | B. String postalCode = . . .
Criteria Builder cb = . . .
Root <Order> order = cq.from (Order.class);
order.join (order_. customer).join(Customer_.addresses);
cq.where (cb.equal (address.get(Address_.postalCode), postalCode));
cq.select (order). Distinct (true);
// query execution code here
|
Option C | C. String postalCode = ...
CriteriaBuilder cb = ...
Root<order> order = cq.from (Order . class) ,
Join<order, Address> address = order.join(Customer_.addresses); cq.where(ct>.equal
(address.get(Address_.postalCode), postalCode)); cq-select(order).distinct(true);
// query execution code here
. . .
|
Option D | D. String postalCode = ...
CriteriaBuilder cb = ...
Root<order> order = cq.from (Order . class ) ,
Join<order, Address> address = order . join (Order_. customer).join (Customer_.addresses);
cq.where <cb.equal (address.get(Address_.postalCode) , postalCode) ) ; cq.selec:(order).distinct
(true);
// query execution code here
|
Correct Answer | A,D |
Question ID 4603 | Which one of the following queries selects the customer whose order has the highest total price?
|
Option A | A. CriteriaBuilder cb = ...
Criteria Query <Customer> cq = cb.create Query (Customer.class); Root<Customer> c = cq.from(Customer.class);
Join<Customer, Order> o = c.join(Customer__.orders);
cq.select(c).distinct(true);
Subquery<Double> sq = cq.subquery(Double.class); Root<Order> subo = cq.correlate(o); sq.select(cb.max(subo.get(Order_.totalPrice))); cq.where(cb.equal(o.get(Order_.totalPrice), cb.all(sq)));
|
Option B | B. CriteriaBuilder cb = ...
CriteriaQuery<Customer> cq = cb.createquery(customer.class)
Root<Customer> c = cq.from(Customer.class);
Join<Customer, Order> o = c.join(Customer__.orders); cq.select(c).distinct(true);
Subquery<Double> sq = cq.subquery(Double.class); Root<Order> subo = cq.correlate(o); sq.select(cb.max(subo.get(Order_.totalPrice))); cq.where(cb.equal(o.get(Order_.totalPrice), cb.all(sq)));
|
Option C | C. CriteriaBuilder cb = ...
CriteriaQuery<Customer> cq = cb.cteateQuery(Customer.class); Root<Customer> c = cq.from(Customer.class);
Join<Customer, Order> o = c.join(Customer__.orders); cq.select(c).distinct(true);
Subquery<Double> sq = cq.subquery(Double.class); Root<Order> subo = cq.correlate(o); sq.select(cb.max(subo.get(Order_.totalPrice))); cq.where(cb.equal(o.get(Order_.totalPrice), cb.all(sq)));
|
Option D | D. CriteriaBuilder cb = ...
CriteriaQuery<Customer> cq = cb.createQuery(Customer.class); Root<Customer> c = cq.from(Customer.class); Join<Customer, Order> o = c.join(Customer_.orders); cq.select(c).distinct(true);
Subquery<Double> sq = cq.subquery(Double.class); Root<Order> subo = sq.from(Order.class);
sq.select (cb.max ( subo.get (Order_ . Total Price) ) ) ; cq.where(sq.all(o.get(Order_.totalPrice)));
|
Correct Answer | D |