在Hibernate中,是否可以使用实际值而不是问号来打印生成的SQL查询?
如果Hibernate API无法实现,您建议如何打印带有真实值的查询?
在Hibernate中,是否可以使用实际值而不是问号来打印生成的SQL查询?
如果Hibernate API无法实现,您建议如何打印带有真实值的查询?
您需要为以下类别启用logging:
org.hibernate.SQL
- set to debug
to log all SQL DML statements as they are executedorg.hibernate.type
-设置为trace
以记录所有JDBC参数因此,log4j配置可能看起来像:
# logs the SQL statements
log4j.logger.org.hibernate.SQL=debug
# Logs the JDBC parameters passed to a query
log4j.logger.org.hibernate.type=trace
第一个相当于hibernate.show_sql=true
个传统property,第二个相当于prints the bound parameters among other things.个
另一个解决方案(非基于hibernate)是使用JDBC代理驱动程序,比如P6Spy.