这个问题在这里已有答案:
如果我订
<property name="show_sql">true</property>
在控制台的 hibernate.cfg.xml 配置文件中,我可以看到SQL .
但它不是真正的SQL ......我能看到将直接传递给数据库的SQL代码吗?
例:
我知道了
select this_.code from true.employee this_ where this_.code=?
我可以看吗
select employee.code from employee where employee.code=12
真正的SQL?
5 回答
如果你想看到直接发送到数据库的SQL(你的示例格式为 similar ),你将不得不使用某种类型的jdbc驱动程序代理,如P6Spy(或log4jdbc) .
或者,您可以启用以下类别的记录(在此处使用
log4j.properties
文件):第一个相当于
hibernate.show_sql=true
,第二个打印绑定参数 .参考
Hibernate 3.5核心文档
3.5. Logging
Hibernate 4.1核心文档
4.1. Logging
log4j.properties
hibernate.cfg.xml
persistence.xml
一些框架使用
persistence.xml
:如果您已经可以看到正在打印的SQL,那意味着您在hibernate.cfg.xml中有以下代码:
要同时打印绑定参数,请将以下内容添加到log4j.properties文件中:
值得注意的是,您看到的代码按原样发送到数据库,查询将单独发送以防止SQL注入 . AFAIK?标记是占位符,由数据库的数字参数替换,而不是由休眠 .
select this_.code from true.employee this_ where this_.code=?
is 将发送到您的数据库的内容 .this_
是employee
表的该实例的别名 .