Let's use the same query as the other article:
SELECT new com.arizal.flight.FlightNumber" +
"(f.number, f.airline) " +
" FROM Flight f WHERE f.departure.code='SYD'")
" FROM Flight f WHERE f.departure.code='SYD'")
This can be expressed using Criteria as follow:
public static void main(String args[]) { cb.createQuery(FlightNumber.class); |
Yeah, but let's see closer. Unlike SQL where we do first the selection followed by FROM (e.g. SELECT number, airline FROM flight), CriteriaBuilder imposes the use of FROM first (Root<Flight> flight = criteriaQ.from(Flight.class);) followed by select.
We do then: FROM flight SELECT number, airline.
Could have been better, don't you think ?
Oh, yes. The code works for both Hibernate and EclipseLink. Hibernate does not suffer from this bug: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5348
No comments:
Post a Comment