Search code examples
javamysqljpaeclipselinkcriteria-api

How to debug JPA CriteriaBuilder queries


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.


Solution

  • 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?