无法阻止Hibernate将日志写入控制台(log4j.properties没问题)

dmi*_*aev 21 java orm hibernate

我已经准备好了

<property name="show_sql">false</property>
Run Code Online (Sandbox Code Playgroud)

我已经禁用了log4j.properties中的所有消息

但是Hibernate使用所有查询和语句写入控制台.

Pas*_*ent 23

设置hibernate.show_sqlto true告诉hibernate将所有SQL语句写入控制台.这是将日志类别设置org.hibernate.SQL为debug 的替代方法.

因此,即使您将此属性设置为false,也要确保没有定义以下类别(或配置为使用控制台appender):

log4j.logger.org.hibernate.SQL=DEBUG
Run Code Online (Sandbox Code Playgroud)

此外,确保hibernate.show_sql在实例化Configuration对象时不以编程方式将其设置为true .像这样的东西:

Configuration cfg = new Configuration().configure().
    .setProperty("hibernate.show_sql", "true");
Run Code Online (Sandbox Code Playgroud)

请注意,setProperty(String propertyName, String value)将第一个参数作为配置属性的全名,即hibernate.show_sql不仅仅是show_sql.