Using Hibernate (4.3.8) with MySQL, I noticed a bunch of SHOW WARNINGS
statements taking considerable bandwidth in the activity log:
I searched around and it's a pretty common issue (for example) that can apparently be resolved by increasing the log level to ERROR (and that solution is confirmed implemented since at least 4.3.6).
The problem is, I don't actually know how to do this. My knowledge of Hibernate is about the bare minimum necessary to work with it. The previously linked post solved it by editing Logback settings in logback.xml
but I'm not using Logback. I'm using all the default settings:
System.err
.So I'm not actually sure how to do this. Here is my configuration file:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/xxxxx</property>
<property name="connection.username">xxxxx</property>
<property name="connection.password">xxxxx</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.isolation">2</property>
<property name="connection.pool_size">10</property>
<property name="current_session_context_class">thread</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- <property name="show_sql">true</property> -->
<!-- <property name="hbm2ddl.auto">create</property> -->
<mapping resource="hibernate.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Here are the dependencies in the build path; there's Jettison and Joda, the MySQL driver, and then everything from Hibernate's required
dependency directory and nothing else:
How do I increase the log level or otherwise disable SHOW WARNINGS
in this (default settings) case? This mentions "log categories of interest" but I'm not sure how those relate to the configuration file. This page doesn't have any log related properties documented outside the "Logging" section, which mentions SLF4J, but apparently I'm not using SLF4J (how could I be, since it's not in my classpath).
The hibernate framework enables the MySQL's SHOW WARNING by default with every query fired, this doubles the number of queries to MySQL and application can realise performance issues. This additional logging of SHOW WARNING by hibernate can be established at -
org.hibernate.engine.jdbc.spi.SqlExceptionHelper#handleAndClearWarnings()
Solution
Make hibernate choose a proper logger. This can be done by adding :
-Dorg.jboss.logging.provider=slf4j
or -Dorg.jboss.logging.provider=log4j
as a JVM runtime parameter.
For slf4j logger, you will need to configure logback.xml
file. Add this :
<logger name="org.hibernate.type" level="ERROR" />
For log4j logger, you will need to add the following line to log4j.properties
:
log4j.logger.org.hibernate.type=ERROR
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With