如何在Hibernate中配置StatementInspector? [英] How I can configure StatementInspector in Hibernate?

查看:1201
本文介绍了如何在Hibernate中配置StatementInspector?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://docs.jboss.org/hibernate/orm/5.2/javadocs/org/hibernate/Interceptor.html 说不赞成onPrepareStatement(String sql).如果要检查和更改SQL语句,请提供StatementInspector.

https://docs.jboss.org/hibernate/orm/5.2/javadocs/org/hibernate/Interceptor.html says that onPrepareStatement(String sql) is Deprecated. Supply a StatementInspector instead, if you wish to inspect and alter SQL statements.

但是我不清楚如何在应用程序级别的Hibernate中配置StatementInspector(我不想在每个休眠会话级别进行设置).

But I am not clear how I can configure StatementInspector in Hibernate at application level (i don't want to set it at each hibernate session level).

推荐答案

不要那样做

您只需要两件事:

  1. 将属性添加到persistence.xml:

属性名称="hibernate.session_factory.statement_inspector" value =标准类名"

property name="hibernate.session_factory.statement_inspector" value="full-qualified class name"

  1. 通过实现org.hibernate.resource.jdbc.spi.StatementInspector接口来编写您的侦听器类.

利润!

这篇关于如何在Hibernate中配置StatementInspector?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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