2

Possible Duplicate:
Print query string in hibernate with parameter values

I am using Hibernate as the persistence layer. And I am setting show_sql to true in order to see the debug info.

However, I am not actually seeing the complete info, because most of the SQL statements as like:

insert 
into
    Address
    (address1, address2, city, province) 
values
    (?, ?, ?, ?)

the parameters are all a question mark, though I can see some actual data in some select statement's condition part.

I want the info like:

insert 
into
    Address
    (address1, address2, city, province) 
values
    ("XXX address1", "XX address2", "XXX city", "XXX province")

How can I configure to see those parameter data, or is this a deficiency in hibernate ??

Community
  • 1
  • 1
xiaohan2012
  • 9,870
  • 23
  • 67
  • 101

1 Answers1

5

Hibernate cannot log the SQL and its parameters in the same line like you want . The logging provided by the Hibernate (by setting log4j.logger.org.hibernate.SQL=debug and log4j.logger.org.hibernate.type=trace in the log4j configuration) can only log the SQL and the parameters in the different lines likes this :

insert 
into
    Address
    (address1, address2, city, province) 
values
    (?, ?, ?, ?)
binding parameter [1] as [VARCHAR] - xxxxxx
binding parameter [2] as [VARCHAR] - xxxxxx
binding parameter [3] as [VARCHAR] - xxxx

You have to use JDBC proxy driver if you want to log the SQL with the parameters in the same line. I have tried log4jdbc and it can do it ,and it also can log the time spent by every SQL statement and log the lines in the code that cause the SQL statements .

You can refer to this blog for more information.

Ken Chan
  • 84,777
  • 26
  • 143
  • 172