问题描述
在Hibernate中,是否可以使用实际值而不是问号打印生成的SQL查询?
如果不是真实值,您会如何建议打印查询?使用Hibernate API可能吗?
您需要启用以下类别:
- code>来记录所有JDBC参数所以,一个log4j配置可能如下所示:
$ b b $ b#记录SQL语句
log4j.logger.org.hibernate.SQL = debug
#记录传递给的JDBC参数查询
log4j.logger.org.hibernate.type = trace
第一个相当于 hibernate.show_sql = true 传统,第二个打印绑定参数。
另一种解决方案(基于非hibernate)将使用JDBC代理驱动程序,如。
Is it possible in Hibernate to print generated SQL queries with real values instead of question marks?
How would you suggest to print queries with real values if it is not possible with Hibernate API?
解决方案You need to enable logging for the the following categories:
- org.hibernate.SQL - set to debug to log all SQL DML statements as they are executed
- org.hibernate.type - set to trace to log all JDBC parameters
So a log4j configuration could look like:
# logs the SQL statements log4j.logger.org.hibernate.SQL=debug # Logs the JDBC parameters passed to a query log4j.logger.org.hibernate.type=trace
The first is equivalent to hibernate.show_sql=true legacy property, the second prints the bound parameters among other things.
Another solution (non hibernate based) would be to use a JDBC proxy driver like P6Spy.
这篇关于如何在使用Hibernate时打印带有参数值的查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!