hibernate输出的sql日志里匹配上传进去的参数(原创)
hibernate在hibernate.cfg.xml里配置了<property name="show_sql">true</property>之后,
可以在控制台输出:select this_.id as id3_0_, this_.type as type3_0_, this_.name as name3_0_ from resources.type this_ where (this_.type=? and this_.name=?)
说要把里面的?穿进去的参数也显示出来,方便我们做测试,查错,该怎么办?
1.已经在hibernate.cfg.xml里配置了<property name="show_sql">true</property>
2.在log4j的log4j.properties里写作:
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=error, stdout
log4j.logger.org.hibernate.type=TRACE
log4j.logger.org.hibernate.sql=TRACE
log4j.logger.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
PS:我使用的hibernate3.3+log4j+slf.jar来进行日志记录的。
最终输出结果见附件