本站首页    管理页面    写新日志    退出


«August 2025»
12
3456789
10111213141516
17181920212223
24252627282930
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


阅读全文(7435) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.266 second(s), page refreshed 144769712 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号