寻求Hibernate调试信息改进 [英] seeking for Hibernate debug info improvement
问题描述
可能重复:
使用参数值在hibernate中打印查询字符串
我使用Hibernate作为持久层。而且我将 show_sql 设置为 true 以查看调试信息。
但是,我实际上并不是看到完整的信息,因为大多数SQL语句如下所示:
将
插入
地址
(地址1,地址2,城市,省)
值
(?,?,?,?)
这些参数都是一个问号,虽然我可以在某些select语句的条件部分看到一些实际的数据。
我想要的信息如下所示:
将
插入
地址
(address1,address2,city,province)
值
(XXX地址1,XX地址2,XXX城市,XXX省)
如何配置查看这些参数数据,或者这是hibernate中的缺陷
?
Hibernate无法像您想要的那样将SQL及其参数记录在同一行中。 Hibernate提供的日志记录(通过设置 log4j.logger.org.hibernate.SQL = debug
和 log4j.logger.org.hibernate.type = log4j配置中的跟踪
)只能记录SQL和不同行中的参数,如下所示:
地址
(地址1,地址2,城市,省)
值
(?,?,?,?)
绑定参数[1]作为[VARCHAR] - xxxxxx
绑定参数[2]为[VARCHAR] - xxxxxx
绑定参数[3]为[VARCHAR] - xxxx
如果要使用同一行中的参数记录SQL,则必须使用JDBC代理驱动程序。我已经尝试 log4jdbc ,它可以这样做,它也可以记录每个SQL语句并记录导致SQL语句的代码行。
您可以参考这个 blog 获取更多信息。
Possible Duplicate:
Print query string in hibernate with parameter valuesI am using Hibernate as the persistence layer. And I am setting show_sql to true in order to see the debug info.
However, I am not actually seeing the complete info, because most of the SQL statements as like:
insert into Address (address1, address2, city, province) values (?, ?, ?, ?)
the parameters are all a question mark, though I can see some actual data in some select statement's condition part.
I want the info like:
insert into Address (address1, address2, city, province) values ("XXX address1", "XX address2", "XXX city", "XXX province")
How can I configure to see those parameter data, or is this a deficiency in hibernate ??
解决方案Hibernate cannot log the SQL and its parameters in the same line like you want . The logging provided by the Hibernate (by setting
log4j.logger.org.hibernate.SQL=debug
andlog4j.logger.org.hibernate.type=trace
in the log4j configuration) can only log the SQL and the parameters in the different lines likes this :insert into Address (address1, address2, city, province) values (?, ?, ?, ?) binding parameter [1] as [VARCHAR] - xxxxxx binding parameter [2] as [VARCHAR] - xxxxxx binding parameter [3] as [VARCHAR] - xxxx
You have to use JDBC proxy driver if you want to log the SQL with the parameters in the same line. I have tried log4jdbc and it can do it ,and it also can log the time spent by every SQL statement and log the lines in the code that cause the SQL statements .
You can refer to this blog for more information.
这篇关于寻求Hibernate调试信息改进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!