问题描述
我想在Hibernate中执行审计日志生成的SQL语句。我编写了可以扩展EmptyInterceptor的自定义拦截器。我重写了 onPrepareStatement 方法来获取生成的SQL。但是当我调试这段代码的时候,我只得到了没有这个参数的生成的SQL。 INSERT INTO TableA(Col1,Col2,Col3 )VALUES(?,?,?)
如何获取包含参数值的完整SQL语句这个来自Hibernate
INSERT INTO TableA(Col1,Col2,Col3)VALUES(Value1,Value2,Value3 )
在hibernate cfg中,可以设置hibernate.show_sql属性设置为true,这将导致Hibernate向stdout输出perpared语句(没有绑定到查询的参数值)。
具有预编译语句和参数列表绑定到他们的日志记录,在commons-logging(或基础日志系统)配置中设置log4j.logger.org.hibernate.SQL = DEBUG。
I want to do audit logging generated SQL statements in Hibernate. I wrote Custom Interceptor that extents EmptyInterceptor. I overrided onPrepareStatement method to get generated SQL. But When I debug this code I am only getting generated SQL without parameters like this.
INSERT INTO TableA(Col1,Col2,Col3) VALUES(?,?,?)
How can I get full SQL statement that contains parameter values like this from Hibernate
INSERT INTO TableA(Col1,Col2,Col3) VALUES("Value1","Value2","Value3")
In hibernate cfg, you may set hibernate.show_sql property to true, this will cause Hibernate to output the perpared statements (without the parameter values bound to a query) to stdout.
To have the precompiled statements and list of parameters bound to them logged, set log4j.logger.org.hibernate.SQL=DEBUG in your commons-logging (or underlying log system) configuration.
这篇关于休眠SQL审计日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!