Hibernate SQL logging

If you need to log SQL queries generated by Hibernate together with parameter values you do not need P6Spy. It is enough to set-up log4j or your favorite logging framework like this


Then you will see everything in your log. For example:

7820 DEBUG [org.hibernate.SQL] {main} - insert into Client (name, personalNumber, id) values (?, ?, ?)
7821 TRACE [org.hibernate.type.StringType] {main} - binding 'John Doe' to parameter: 1
7821 TRACE [org.hibernate.type.StringType] {main} - binding '123X' to parameter: 2
7821 TRACE [org.hibernate.type.LongType] {main} - binding '10' to parameter: 3

Tags: , ,

2 Responses to “Hibernate SQL logging”

  1. Tomasz Bartczak Says:

    Or You could use log4jdbc http://code.google.com/p/log4jdbc/ which gives You better view on the real SQL

  2. miluch Says:

    Actually pure P6Spy is very old and it looks it is not active anymore. I personally used p6 spy patched version since the original version logs too much, just ignores your configuration settings.