Debugging “Hibernate bind parameters not getting logged”

I did set org.hibernate.type=trace. But it still didn’t print bind parameters. So decided to debug through the hibernate source code.  The code for logging the bind parameters exists in org.hibernate.type.NullableType.nullSafeSet(PreparedStatement, Object, int). Found that it is infact logging the bind parameters. But I still don’t see those in the log file or the console. I might have to dig deeper into the org.slf4j.Logger.trace method.

The issue turned out to be with the appender and the appender threshold. We have 3 appenders in our log4j configuration and we were using only one of the the 3 for the category “org.hibernate.type”. And this appender had threshold set WARN, as a result it kept supressing all the “trace” logs. Another thing you need to be careful about this is that you need to initialize log4j before calling hibernate API. This is because hibernate determines the log level at class load time using the following statement:
private static final boolean IS_VALUE_TRACING_ENABLED = LoggerFactory.getLogger( StringHelper.qualifier( Type.class.getName() ) ).isTraceEnabled();

Advertisements