Hibernate: how to show SQL in logs

When debugging it could be useful to see what are the queries Hibernate executes. To do so there are some ways of enabling debug logging:

Using Log4J configuration

log4j.logger.org.hibernate.SQL=DEBUG

(in Liferay: you can change it from the admin panel without restarting the server)

Modifying Hibernate XML configuration

You need to change the factory bean that handles Hibernate sessions (a subclass of LocalSessionFactoryBean).

<property name="hibernateProperties">
  <props>
    <property name="show_sql">true</property> 
    <property name="format_sql">true</property> 
    <property name="use_sql_comments">true</property>
  </props>
</property>

One thought on “Hibernate: how to show SQL in logs

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s