<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/test</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<mapping resource="com/hejian/hibernate/domain/Event.hbm.xml"/>
<mapping resource="com/hejian/hibernate/domain/Person.hbm.xml"/>
</session-factory>
</hibernate-configuration>
hibernate用logger4j生成了大量的日志,很繁琐。如果想屏蔽有几种方法:
(一)将配置文件的show_sql属性设置为false:如在.cfg.xml里加入
<property name="show_sql">false</property> 一句。
这样只能禁止输出sql语句,但不能屏蔽其他调试信息。
由于hibernate的lib没有包含log4j的jar包,所以引入。
把log4j.properties 放到classpath下。
(二)要想进一步减少日志的输出,还得在 log4j.properties 加入如下几句:
#总级别为DEBUG,这样可以打印我们自己添加的调试信息
log4j.rootLogger=DEBUG, stdout
log4j.logger.org.apache=WARN
log4j.logger.com.opensymphony=WARN
log4j.logger.net.sf=WARN
log4j.logger.org.hibernate=WARN
#可单独将SQL包设置为DEBUG 级别
log4j.logger.org.hibernate.SQL=DEBUG
(三)一般还要加入如下设置(这些产生的日志也相当客观):
log4j.logger.org.apache=WARN
log4j.logger.org.apache.catalina=ERROR
log4j.logger.org.apache.commons=WARN