Page 1 of 1

About Question enthuware.oce-jpad.v6.2.578 :

Posted: Wed Sep 02, 2015 5:11 pm
by crolip
On this option:

Code: Select all

CriteriaQuery q = cb.createQuery();
 Root<Order> c = q.from(Order.class); 
Join<Order, Customer> o = c.join(Order_.customer); 
q.orderBy(cb.asc(o.get(Order_.quantity)).asc(c.get(Customer_.name)));
 q.select(cb.tuple(o, c.get(Customer_.name)));
Are said: Since it is specified in the problem statement that Customer/Order is a unidirectional relationship, you should assume that there is no customer field in Order. Therefore, you cannot join order with customer. Had the relationship been bidirectional, this would have been a valid option.

But, asc() and desc() methods are available in CriteriaBuilder and not on Path?

Re: About Question enthuware.oce-jpad.v6.2.578 :

Posted: Wed Sep 02, 2015 7:16 pm
by admin
Yes, asc and dsc are present in CriteriaBuilder: https://docs.oracle.com/javaee/6/api/ja ... xpression)

Re: About Question enthuware.oce-jpad.v6.2.578 :

Posted: Thu Sep 03, 2015 7:29 pm
by crolip
Ok, so we could not use asc from Path.

q.orderBy(cb.asc(o.get(Order_.quantity)).asc(c.get(Customer_.name)));

Re: About Question enthuware.oce-jpad.v6.2.578 :

Posted: Thu Sep 03, 2015 8:36 pm
by admin
You are right. That would be wrong as well.
thank you for your feedback!