How to view the SQL queries issued by JPA?
When my code issues a call like this:
entityManager.find(Customer.class, customerID);
How can I see the SQL query for this call? Assuming I don't have access to database server to profile/monitor the calls, is there way to log or view within my IDE the corresponding SQL queries issued by JPA calls? I'm going against SQL Server 2008 R2 using the jTDS driver.
Logging options are provider-specific. You need to know which JPA implementation do you use.
-
Hibernate (see here):
<property name = "hibernate.show_sql" value = "true" />
-
EclipseLink (see here):
<property name="eclipselink.logging.level" value="FINE"/>
-
OpenJPA (see here):
<property name="openjpa.Log" value="DefaultLevel=WARN,Runtime=INFO,Tool=INFO,SQL=TRACE"/>
-
DataNucleus (see here):
Set the log category
DataNucleus.Datastore.Native
to a level, likeDEBUG
.
Also, if you're using EclipseLink and want to output the SQL parameter values, you can add this property to your persistence.xml file:
<property name="eclipselink.logging.parameters" value="true"/>