无法使hibernate停止使用Spring JPA Vendor Adapter显示SQL

Moj*_*ojo 15 spring hibernate jpa

Hibernate继续向stdout发送SQL跟踪,当隐藏在JPA适配器后面时,我无法弄清楚如何更改Hibernate配置属性.这是entityManagerFactory的Spring bean:

<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>
Run Code Online (Sandbox Code Playgroud)

即使将showSql属性设置为false,Hibernate也会继续打印SQL.

我已经尝试使用"hibernate.show_sql = false"在我的类路径中创建一个hibernate.properties文件,但它也没有选择它.

NA.*_*NA. 20

尝试在persistance.xml中设置它

<persistence>
  <persistence-unit name="PU">
    <properties>
      <property name="hibernate.show_sql" value="false"/>
    </properties>
  </persistence-unit>
</persistence>
Run Code Online (Sandbox Code Playgroud)

  • 还要在“主”类上查找“ @DataJpaTest(showSql = true)”注解。不过,这与Spring Boot有所不同:[org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest](https://docs.spring.io/spring-boot/docs/current/api/index.html? org / springframework / boot / test / autoconfigure / orm / jpa / DataJpaTest.html) (2认同)

nav*_*vee 9

<property name="jpaProperties">
    <props>
        <prop key="hibernate.show_sql">false</prop>
    </props>
</property>
Run Code Online (Sandbox Code Playgroud)

这也行