休眠SQL审计日志记录 [英] Hibernate SQL Audit Logging

查看:85
本文介绍了休眠SQL审计日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在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审计日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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