12

I have configured my pom.xml to include slf4j and bindings to log4j and exclude commons-logging as explained here and disabled Hibernate's own logging as explained here.

I can suppress Spring's own messages, but Hibernate messages still come out despite my log4j.properties settings below.

log4j.debug=false
log4j.rootCategory=WARN, stdout
log4j.category.org.hibernate=ERROR, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%p %t %c - %m%n
log4j.category.org.springframework = ERROR
log4j.category.org.hibernate = ERROR

Here is my pom.xml file:

What could be the issue? I am seeing all the sql messages hibernate generates.

Community
  • 1
  • 1
ustun
  • 6,941
  • 5
  • 44
  • 57
  • If you're using it, you might need to set `false` in your hibernate configuration file. – Xavi López Oct 28 '11 at 13:04
  • @XaviLópez Thanks, I had actually a similar one in my Spring application context, and setting it there solved the problem. I would mark your deleted answer as the answer. I find it still a bit strange that disabling in log4j's properties is not enough to suppress Hibernate's log messages, but this is Java EE, I shouldn't keep my hopes that high, should I? – ustun Oct 28 '11 at 13:21
  • I've undeleted the answer. I'd advice to post your own answer with the particular problem you had, and how you solved it. You can upvote mine if it helped you, of course :) From the Hibernate Reference, using `show_sql=true` is equivalent to using `log4j.logger.org.hibernate.SQL=DEBUG`. Maybe it was overwriting the trace level for the `SQL` subpackage. I don't have the means to test this now, but maybe someone else can shed some light on this :] – Xavi López Oct 28 '11 at 17:28

5 Answers5

15

If anyone looks up this question while browsing for answers:

IF you are using spring-boot-starter-data-jpa, set spring.jpa.show_sql = false in your application.properties file.

Jørgen Skår Fischer
  • 883
  • 1
  • 10
  • 22
11

Complementing Jørgen Skår Fischer's answer, in my specific case I had to add both settings in the application.properties file.

spring.jpa.show-sql=false 

and

spring.jpa.properties.hibernate.show_sql=false
Leonardo Savio
  • 399
  • 4
  • 7
  • 1
    The second line helped me get rid of the hibernate messages (I had the first line already set, but was still receiving the hibernate log messages). – Voronin Nov 07 '21 at 13:13
7

If you're using it, you might need to set <property name="show_sql">false</property> in your hibernate configuration file.

Xavi López
  • 27,550
  • 11
  • 97
  • 161
4

For those users who tried everything proposed and still saw the sql logs:

If you annotated your test with @DataJpaTest, set the (not so obvious) showSql-field inside to false.

@DataJpaTest(showSql = false)
Neo
  • 1,869
  • 1
  • 7
  • 20
2

And if you still can't disable show_sql try something like this

logging.level.org.hibernate.SQL=INFO
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=INFO
Carlos Lacerda
  • 699
  • 6
  • 14