简体   繁体   中英

How to configure Hibernate logging?

The sample application I am developing keeps writing all the Hibernate queries to Tomcat console. I mean if you start Tomcat on Windows, you will have a small applet kind of window opened up. Hibernate keeps writing all data access code like 'Hibernate: select table10_.col1 as COL10_, table10_.col2 as COL20_,..." I was wondering if there is any configuration I can set for Hibernate to write these queries to some kind of log file? Possibly to localhost-log under tomcat/logs?

That's not logging, it's Hibernate's "show_sql". Look for a property named "hibernate.show_sql" being set to "true". Change it to false or just remove it entirely to get rid of those. Then see the the Configuration chapter in the Hibernate ref for how to set up SQL logging in Hibernate.

@Ryan-Stewart is right but it can be a Pass through Java JDBC driver that can log SQL and/or JDBC calls for other JDBC drivers.

With hibernate's logging you have logging similar to :

 select bs0_.A_REF as A2_7_0_ from B bs0_ where  bs0_.other = 0 and bs0_.A_REF=?  
 TRACE 2011-08-  03 00:30:45,317 binding '123' to parameter: 1

Note the '?' instead of the real parameter value.

With Pass through JDBC driver you have logging similar to :

select bs0_.A_REF as A2_7_0_ from B bs0_ where  bs0_.other = 0 and bs0_.A_REF=123  

All the bind parameter are resolved.

log4jdbc is one of those pass through JDBC driver.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM