如何调试 JPA CriteriaBuilder 查询
如何调试使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
persistence.xml 中还打印从常规 JPQL 查询生成的 SQL 的相同属性,也应该打印从 Criteria 查询生成的 SQL。
例如,
对于 Hibernate(例如 JBoss AS 使用),它是:
对于 EclipseLink(例如 GlassFish 使用),它是:
另请参阅:如何查看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:
For EclipseLink (used by e.g. GlassFish) it's:
Also see: How to view the SQL queries issued by JPA?
如果您使用 Java 和 Spring,在资源下,您可以调整
application.properties
文件并添加以下行:If you are using Java and Spring, under resources, you can adjust your
application.properties
file and add the line below: