How to setup SQL logging for JPA

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"/>
  • <property name="eclipselink.logging.level.sql" value="FINE"/>
  • <property name="eclipselink.logging.parameters" value="true"/>
  • 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, like DEBUG.
It also depends on your application server's logging setting. For example, for Glassfish/Payara:
you may need to configure the actual logging values in GlassFish’s logging.properties file.

Assuming you have a domain called domain1:

Edit $GLASSFISH_HOME/glassfish/domains/domain1/config/logging.properties and add the following lines:

org.eclipse.persistence.level = FINE
org.eclipse.persistence.sql.level = FINE

The first allows you to see SQL statements.  The second must be set in order for SQL parameters to be seen, but it is not sufficient on its own.
You can add following too:

org.eclipse.persistence.session.level=INFO

Comments

Popular posts from this blog

Check MySQL query history from command line