从Hibernate查询获取SQL字符串 [英] Get SQL String from Hibernate query

查看:251
本文介绍了从Hibernate查询获取SQL字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从Hibernate查询中获取字符串并稍后处理它(所以我不能用hibernate.show_sql)解决它。



我已经看过如何从Hibernate Criteria API中获取SQL(*不是*用于日志记录),但是使用该解决方法我得到了SQL查询字符串,但不显示参数值,它显示'?'...有什么办法可以得到完整的SQL字符串的参数值?



我的意思是,用这个解决方案我得到SELECT * FROM USER WHERE NAME =?AND SURNAME =?但我需要获得SELECT * FROM USER WHERE NAME ='John'AND SURNAME ='Doe' ...



想法

解决方案

称为 p6spy 。这有点旧了,我担心它不再被维护。无论如何,它在过去给了我很好的结果。

编辑:刚发现它正在被积极开发。像我的魅力一样工作!


I need to get the string from an Hibernate query and process it later (so I can't solve it with "hibernate.show_sql").

I have already looked at How to get SQL from Hibernate Criteria API (*not* for logging) but with that workaround I get the SQL query string but instead of showing the parameters value it shows '?'... Is there any way to get the full SQL string with the parameters values?

I mean, with that solution I get "SELECT * FROM USER WHERE NAME=? AND SURNAME=?" but I need to get "SELECT * FROM USER WHERE NAME='John' AND SURNAME='Doe'"...

Ideas?

解决方案

There is a tool called p6spy. It's a bit older and I am afraid it isn't maintained anymore. It gave me good results in the past, anyway.

Edit: just found that it is being actively developed again. Works like a charm for me!

这篇关于从Hibernate查询获取SQL字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆