Can't make hibernate stop showing SQL using Spring JPA Vendor Adapter


Can't make hibernate stop showing SQL using Spring JPA Vendor Adapter



Hibernate is continuing to spew SQL traces to stdout, and I can't figure out how to change a Hibernate configuration property when it's hidden behind a JPA adapter. This is the Spring bean for the entityManagerFactory:

<bean id="entityManagerFactory"      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">     <property name="dataSource" ref="ssapDataSource"/>     <property name="jpaVendorAdapter">         <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" >             <property name="showSql" value="false"/>         </bean>     </property> </bean> 

Even with the showSql property set to false, Hibernate keeps printing SQL.

I've tried making a hibernate.properties file in my classpath with "hibernate.show_sql=false", but it didn't pick that up either.




Is there a way to get a list of all the Spring application contexts running in the JVM?

1:



Combining namespace based configuration with different authentication methods in spring-security
Try setting it in persistance.xml.
Spring MVC form:select Tag, multiple selections not binding correctly?
<persistence>   <persistence-unit name="PU">     <properties>       <property name="hibernate.show_sql" value="false"/>     </properties>   </persistence-unit> </persistence> 


Simple Spring, use of ClasspathApplicationContext for standalone apps, how to reuse?


What should I learn first, Spring or Hibernate? [closed]

2:



What is best way to learn Spring AOP or AOP in general?
<property name="jpaProperties">     <props>         <prop key="hibernate.show_sql">false</prop>     </props> </property> 
this will also work.
What are all the portlet classes in Spring mvc?


portlet 2.0 (jsr286) development with spring

3:


As far as I know, Hibernate will also log SQL statements if logging for org.hibernate.SQL happens at DEBUG or ALL level, so you could try disabling that (for example with log4j.logger.org.hibernate.SQL=info when using Log4J)..


4:


If you are using spring make sure that you don't have the showSql property set to true. I was doing this myself.
<bean id="vendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">     <property name="showSql" value="false"/> </bean> 


5:


add this to your log4j.properties.
log4j.logger.org.hibernate = WARN 


6:


This worked for me:.
spring.jpa.show-sql=false 


7:


Here are three ways (they are probably others) to show or hide hibernate sql queries :.
  1. In logger config (level DEBUG for logback) :.
    <logger name="org.hibernate.SQL" level="DEBUG" /> 
  2. In Spring config (for instance in java config) :.
    @Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() { final LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean(); //... 

    final Properties jpaProperties = new Properties(); // java.util //TODO replace "true" by a variable jpaProperties.setProperty("hibernate.show_sql", "true"); lef.setJpaProperties(jpaProperties); return lef; }
  3. In persistence.xml.
    <property name="hibernate.show_sql" value="true" /> 
It seems that the logger configuration is independant from the persistence configuration.

As for the persistence configuration it appears that spring overrides the persistence.xml (I tested it with a persistence.xml loaded by spring, if this is not the case I don't know what will be the behavior).



A difference between the two configurations is the result logging, with logback it will look like this : .
2016-08-25 16:05:39,436 DEBUG org.hibernate.SQL(92) - alter table ...
With the persistence configuration : .
Hibernate: alter table ...



76 out of 100 based on 86 user ratings 886 reviews