简体   繁体   English

将Hibernate 3与Logback结合使用时如何打印确切的SQL查询

[英]How to print exact sql query when using hibernate 3 with logback

I am using logback as logging framework and hibernate 3 as ORM tool. 我正在使用logback作为日志记录框架,并使用休眠3作为ORM工具。 I want to print all the SQL queries exactly the same as it executes in the mysql DB. 我想打印所有与mysql DB中执行的SQL查询完全相同的SQL查询。

I tried with show_sql=true parameter though it only prints the sql but no binding values with it. 我尝试使用show_sql = true参数,尽管它只输出sql,但没有绑定值。

I've gone through the earlier posts and have also tried to put the logger in logback to get the desired result but no luck. 我已经看过较早的文章,并且还尝试将记录器重新登录以获得期望的结果,但是没有运气。

<logger name="org.hibernate.loader.hql" level="TRACE" additivity="false">
    <appender-ref ref="hibernateLogger" />
</logger>

<logger name="org.hibernate.SQL" level="DEBUG" additivity="false">
    <appender-ref ref="hibernateLogger" />
</logger>

Even after defining these loggers and the appenders, sql w/o bindings are being printed on console rather than desired logfile 即使在定义了这些记录器和附加器之后,仍在控制台而不是所需的日志文件上打印不带SQL的绑定

Add this logger 添加此记录器

 <logger name="org.hibernate.type.descriptor.sql.BasicBinder"> 
   <level value="TRACE"/>
 </logger>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM