22

I've already set

<property name="show_sql">false</property>

and I have disabled all messages in log4j.properties

But Hibernate write to console with all queries & statements.

Biscuit128
  • 5,218
  • 22
  • 89
  • 149
dmitrynikolaev
  • 8,994
  • 4
  • 30
  • 45
  • I'm having the same problem. I've set log4j.logger.org.hibernate=INFO and false, but I still get the hibernate SQL added to my log file. I've searched everything in my project for "show_sql" and "log4j" to find any other references, but there aren't any. Is there another way to turn on hibernate logging? – Tauren Mar 02 '10 at 08:28
  • 1
    Sorry for the noise, but I was wrong -- doing the things I mentioned DO remove all SQL logging. I discovered that a 3rd-party library I am using has this line hard coded in it: System.out.println(hql); Yikes. – Tauren Mar 02 '10 at 09:02
  • possible duplicate of [Can't make hibernate stop showing SQL using Spring JPA Vendor Adapter](http://stackoverflow.com/questions/679518/cant-make-hibernate-stop-showing-sql-using-spring-jpa-vendor-adapter) – Peter Perháč Apr 24 '13 at 08:42

6 Answers6

23

Setting the hibernate.show_sql to true tells hibernate to Write all SQL statements to console. This is an alternative to setting the log category org.hibernate.SQL to debug.

So even if you set this property to false, make sure that you don't have the following category defined (or configured to use a console appender):

log4j.logger.org.hibernate.SQL=DEBUG

Also, make sure that you don't set the hibernate.show_sql programmatically to true when instancing your Configuration object. Hunt something like this:

Configuration cfg = new Configuration().configure().
    .setProperty("hibernate.show_sql", "true");

Note that the setProperty(String propertyName, String value) takes as first parameter the full name of a configuration property i.e. hibernate.show_sql, not just show_sql.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
2

HI there, i figured out you can solve this also with this 2 lines in your log4j.properties file.

log4j.logger.org.hibernate = WARN
log4j.logger.org.hibernate = ERROR
MadMad666
  • 955
  • 3
  • 11
  • 19
1

You adding something like this to log4j.properties?

log4j.logger.org.hibernate = WARN
Droo
  • 3,177
  • 4
  • 22
  • 26
0

It seems very strange, but when Use Eclipse with JUnit Test task, all output still goes to Console (in Eclipse Console window).

But when I use ant command for unit testing, nothing goes to console.

dmitrynikolaev
  • 8,994
  • 4
  • 30
  • 45
0

As mentioned before, you need first to set hibernate.show_sql to false. This will prevent hibernate output to console or Tomcat stdout log.

But in order to direct your sql output to another log use this code in log4j.xml file:

<logger name="org.hibernate.SQL" additivity="false">
    <level value="DEBUG" />
    <appender-ref ref="hibernate"/>
</logger>

To keep the normal hibernate log level (WARN / ERROR) to console use this code in log4j.xml file:

<category name="org.hibernate">
    <priority value="WARN" />
</category>
cgalev
  • 321
  • 2
  • 9
0

Its simple Just Add dependency to your pom.xml file

<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>

And it will disable logging and add put in src/main/resources/log4j.properties file

log4j.rootLogger=OFF

Then you can use it anytime if you want to display log on console then On it or else OFF

karan
  • 24
  • 2