如何在Hibernate中配置StatementInspector? [英] How I can configure StatementInspector in Hibernate?
问题描述
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).
推荐答案
不要那样做
您只需要两件事:
- 将属性添加到persistence.xml:
属性名称="hibernate.session_factory.statement_inspector" value =标准类名"
property name="hibernate.session_factory.statement_inspector" value="full-qualified class name"
- 通过实现org.hibernate.resource.jdbc.spi.StatementInspector接口来编写您的侦听器类.
利润!
这篇关于如何在Hibernate中配置StatementInspector?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!