如何调试 JPA CriteriaBuilder 查询

发布于 2024-12-23 09:26:04 字数 192 浏览 4 评论 0原文

如何调试使用 JPA 2.0 CriteriaBuilder 构建的查询?有没有办法打印出正在执行的查询?

我正在使用 NetBeans、MySql、GlassFish 开发 Web 应用程序。我会避免在调试模式下启动 MySql,因为它也用于其他应用程序。 JPA 提供者是 EclipseLink。

How can I debug a query built with JPA 2.0 CriteriaBuilder? Is there a way to print out the query that is being executed?

I am developing a web application using NetBeans, MySql, GlassFish. I would avoid starting MySql in debug mode, because it is used also for other applications. JPA provider is EclipseLink.

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

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

发布评论

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

评论(2

So尛奶瓶 2024-12-30 09:26:04

persistence.xml 中还打印从常规 JPQL 查询生成的 SQL 的相同属性,也应该打印从 Criteria 查询生成的 SQL。

例如,

对于 Hibernate(例如 JBoss AS 使用),它是:

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

对于 EclipseLink(例如 GlassFish 使用),它是:

<property name="eclipselink.logging.level" value="FINE"/>
<property name="eclipselink.logging.parameters" value="true"/>

另请参阅:如何查看JPA发出的SQL查询?

The same attributes in persistence.xml that also print the SQL that is generated from regular JPQL queries, should also print the SQL that is generated from Criteria queries.

E.g.

For Hibernate (used by e.g. JBoss AS) it's:

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

For EclipseLink (used by e.g. GlassFish) it's:

<property name="eclipselink.logging.level" value="FINE"/>
<property name="eclipselink.logging.parameters" value="true"/>

Also see: How to view the SQL queries issued by JPA?

情独悲 2024-12-30 09:26:04

如果您使用 Java 和 Spring,在资源下,您可以调整 application.properties 文件并添加以下行:

spring.jpa.show-sql=true

If you are using Java and Spring, under resources, you can adjust your application.properties file and add the line below:

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