« | August 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | | | | | | |
| 公告 |
戒除浮躁,读好书,交益友 |
Blog信息 |
blog名称:邢红瑞的blog 日志总数:523 评论数量:1142 留言数量:0 访问次数:9695877 建立时间:2004年12月20日 |

| |
[orm]Hibenrate控制SQL的输出  原创空间, 软件技术, 电脑与网络
邢红瑞 发表于 2005/5/24 10:26:59 |
hibernate可以打印出sql语句,一般是配置文件加<property name="show_sql">true</property>或者直接SessionFactory sf = new Configuration().setProperty("hibernate.show_sql", "true")// ....buildSessionFactory();其实这是不好的做法,有些服务器使用log4控制日志的例如JBOSS必须修改文件才允许访问System.out,还有就是所有的打印输出混淆在一起。其实可以使用log4j的配置,log4j.logger.org.hibernate.SQL=DEBUG, SQL_APPENDERlog4j.additivity.org.hibernate.SQL=falseog4j.properties 只需要放到你的 classpath 中就可以了, 对于 war, 你可以放到 WEB-INF/classes/log4j.additivity.org.hibernate.SQL=false说明这个 Logger 的 appender 不继承它的父Logger 是org.hibernate.SQL和 ROOT Logger, 目的是防止jboss那个xml中定义的ROOT Logger和我们这个log4j.properties中定义的Logger互相干扰. Beware that appenders are not singletons, they are additive! A category inherits all the appenders from its ancestors also (by default). If you add an appender to a category and it writes to the same underlying stream (console, same file etc.) as some other appender, the same log message will appear twice (or more) in the log. In addition, if two categories in a hierarchy are configured to use the same appender name, Log4j will write twice to that appender. Use cat.setAdditivity(false) on a category to disable inheriting of appenders. Then, log messages will only be sent to the appenders specifically configured for that category.良好格式hibernate sql输出 <property name="show_sql">true</property> <property name="format_sql">true</property>log4j文件log4j.logger.org.hibernate.SQL=DEBUG, SQL_APPENDER#只显示启动信息log4j.logger.org.hibernate=INFO# 记录JDBC 绑定参数log4j.logger.org.hibernate.type=INFO |
|
|