Actually, I was wrong.
Probably I had some classes/libraries problem that prevented things from working correctly.
What
tima said was correct, hibernate.show_sql just forces the SQL output to the console (indeed annoying of you don't want that), but want to retrieve the SQL by some other means.
Follow this checklist and you will be able to control what you see in terms of SQL code.
1) set the hibernate.show_sql to false in your connections
2) in your web.xml, add the following
Code:
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.xml</param-value>
</context-param>
and, if you are using Spring, this other fragment
Code:
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
3) add the following file log4j.xml under the WEB-INF/classes directory of your deployed program (forget about the web server's directories)
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="appenderConsole" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.SimpleLayout"/>
</appender>
<appender name="appenderFile" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="/logs/pubh3.javalog"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="500KB"/>
<param name="MaxBackupIndex" value="1"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<appender name="appenderFileDBCon" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="/logs/pubh3.dbcon"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="500KB"/>
<param name="MaxBackupIndex" value="1"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<logger name="org.hibernate.SQL" additivity="false">
<level value="debug" />
<appender-ref ref="appenderFile" />
</logger>
<root>
<level value="info"/>
<appender-ref ref="appenderConsole" />
<appender-ref ref="appenderFile" />
</root>
</log4j:configuration>
As you can see, by taking in and out those appenders in <root>, you can decide what shows or not in the console and in the log file. You could also easily create a new file appender, just for the Hibernate SQL.
4) For good measure, these are my libraries (they should be under WEB-INF/lib of your deployed application, independently of what you have on your web server:
commons-logging-1.1.1.jar
log4j-1.2.15.jar