title: Find Native SQL Query from TypedQuery
body: <p>I need to know what query is being executed on the database so I can check if I can improve it.</p>
  
  <p>The following code is used to create a query:</p>
  
  <pre><code>TypedQuery&lt;OrderItem&gt; orderItemTypedQuery = typedQuery.setParameter(OrderItemCriteria.CUSTOMER_ID_PARAM, criteria.getCustomerId());
  
  String sqlQuery=orderItemTypedQuery.unwrap(org.hibernate.Query.class).getQueryString();
  </code></pre>
  
  <p>The following query is shown:</p>
  
  <pre><code>select generatedAlias0 from OrderItem as generatedAlias0 left join generatedAlias0.order as generatedAlias1 where ( generatedAlias0.status in (:param0) ) and ( generatedAlias0.hidden=:param1 ) and ( generatedAlias0.customer.id=:param2 ) and ( generatedAlias0.linkedOrderItem is null ) order by generatedAlias1.id desc, generatedAlias0.id desc
  </code></pre>
  
  <p>The query above isn't native (parameteres aren't set), I'm trying to find what is being executed on the database so that I can check if the query is slow and needs to be optimised.</p>
  
  <p>Thanks</p>