Hi!
I have read the book "SQL Tuning" by Dan Tow and want to optimise the important HQL/JPA-QL queries of my application, but I not sure how to enforce the optimal execution plan :-(.
Consider the following JPA-QL-Query:
select o from Operation o where o.order.flight.etd = :flight
select .... from Operation operation0_, OrderTab order1_, Flight flight2_ where order1_.flight_id=flight2_.id and operation0_.order_id=order1_.id and flight2_.etd=?
Query query = em.createQuery(<JPA-QL Query which enforces the join order>); Operation op = (Operation)em.getSingleResult(); ....
Query query = em.createNativeQuery(<SQL Query which enforces the join order>); Object[] ar = (Object[])em.getSingleResult(); /*the result of the query won't be an object with the type Operation but an array of objects (the attribute values)*/ Operation op = (Operation)new Operation().setAttr1(ar[0]).setAttr2(ar[1]) ...;
Query query = em.createNativeQuery(<SQL Query which enforces the join order>); Operation op = (Operation)em.getSingleResult();