JPQL 到 SQL 转换器

发布于 2024-08-24 03:49:36 字数 90 浏览 3 评论 0原文

是否可以访问JPQL生成的SQL?

我想稍后使用 SQL 创建一个用于我的目的的视图。

如果有必要的话我正在使用 Hibernate。

Is it possible to access the SQL which is generated by JPQL?

I would like to use the SQL to later create a view for my purposes.

I am using Hibernate if it matters.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

十年不长 2024-08-31 03:49:36

是否可以访问JPQL生成的SQL?

您可以从 Hibernate Interceptor 访问 SQL String,更准确地说是从方法 Interceptor.html#onPrepareStatement(java.lang.String)

onPrepareStatement

String onPrepareStatement(String sql) Called when sql string is being prepared. Parameters: sql - sql to be prepared Returns: original or modified sql

如果您决定采用这种方式,最好的选择是扩展 EmptyInterceptor 并仅覆盖您想要的方法。

您可以在 persistence.xml 中使用以下声明来挂钩拦截器:

<properties>
  <property name="hibernate.ejb.interceptor" value="com.acme.MyInterceptor"/>
</properties>

Is it possible to access the SQL which is generated by JPQL?

You can access the SQL String from an Hibernate Interceptor, more precisely from the method Interceptor.html#onPrepareStatement(java.lang.String)

onPrepareStatement

String onPrepareStatement(String sql) Called when sql string is being prepared. Parameters: sql - sql to be prepared Returns: original or modified sql

If you decide to go this way, the best option is to extends EmptyInterceptor and to override only the methods you want.

You can hook your interceptor using the following declaration in your persistence.xml:

<properties>
  <property name="hibernate.ejb.interceptor" value="com.acme.MyInterceptor"/>
</properties>
↘人皮目录ツ 2024-08-31 03:49:36

你可以将hibernate.show_sql属性设置为true,那么所有的SQL都会显示在控制台上。

<property name="hibernate.show_sql">true</property>

You can set the hibernate.show_sql property to true, then all the SQL will be shown on the console.

<property name="hibernate.show_sql">true</property>
£噩梦荏苒 2024-08-31 03:49:36

因此,您需要编写自己的 JPQL 实现 :-) 毕竟,将 JPQL 转换为 RDBMS 数据存储的 SQL 就是 JPQL 实现。祝你好运!

当然,您可以利用现有的 JPQL 实现,无论是 Hibernate、EclipseLink 还是 DataNucleus...并且由于它们都是开源的,因此您应该深入研究它们的代码库。

So you need to write your own JPQL implementation then :-) After all, converting JPQL into SQL for an RDBMS datastore is what a JPQL implementation is. Good Luck!

Sure you could make use of an existing JPQL implementation though, whether Hibernate, or EclipseLink, or DataNucleus ... and since they are all open source you ought to go and dig in their codebase.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文