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

2 thoughts on “Hibernate SQL logging

  1. miluch

    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.

Comments are closed.