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_APPENDER log4j.additivity.org.hibernate.SQL=false og4j.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
|
相关推荐
NULL 博文链接:https://javakeith.iteye.com/blog/857028
hibenrate的代码本人的培训的代码,老师讲解的很好。是一个学习hibenrate的好的工具
hibernate很好的学习资料,我学习hibenrate的时候自己总结的,里面有三个案例,一对一、一对多、多对多的三个案例 。 eclipse工具编码设置为utf-8。
Hibernate更新某些字段
hibernahibernate学习资料te学习资料hibernate学习资料v
数据库和配置MySQL 飞路(用于数据迁移) GradleTomcat吉特Google Book API 后端技术JavaSpring MVC,Spring AOP,Spring Security Hibernate ORM,Hibernate Validator,Hibenrate Search(Lucene) 翻新,JSON ...
基于hibernate、struts2、spring、开发项目
公交车查询系统,公交车查询系统 公交车查询系统,公交车查询系统