How can I debug a query built with JPA 2.0
CriteriaBuilder
? Is there a way to print out the query that is being executed?
I am developing a web application using NetBeans
, MySql
, GlassFish
. I would avoid starting MySql in debug mode, because it is used also for other applications. JPA provider is EclipseLink
.
Create an instance of CriteriaBuilder by calling the getCriteriaBuilder() method. Create an instance of CriteriaQuery by calling the CriteriaBuilder createQuery() method. Create an instance of Query by calling the Session createQuery() method. Call the getResultList() method of the query object, which gives us the ...
Interface CriteriaBuilder. Used to construct criteria queries, compound selections, expressions, predicates, orderings. Note that Predicate is used instead of Expression<Boolean> in this API in order to work around the fact that Java generics are not compatible with varags.
The same attributes in persistence.xml that also print the SQL that is generated from regular JPQL queries, should also print the SQL that is generated from Criteria queries.
E.g.
For Hibernate (used by e.g. JBoss AS) it's:
<property name="hibernate.show_sql" value="true" />
For EclipseLink (used by e.g. GlassFish) it's:
<property name="eclipselink.logging.level" value="FINE"/>
<property name="eclipselink.logging.parameters" value="true"/>
Also see: How to view the SQL queries issued by JPA?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With