如何查看JPA发出的SQL查询? [英] How to view the SQL queries issued by JPA?

查看:59
本文介绍了如何查看JPA发出的SQL查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的代码发出这样的调用时:

When my code issues a call like this:

entityManager.find(Customer.class, customerID);

如何查看此调用的 SQL 查询?假设我无权访问数据库服务器来分析/监视调用,有没有办法在我的 IDE 中记录或查看 JPA 调用发出的相应 SQL 查询?我反对使用 jTDS 驱动程序的 SQL Server 2008 R2.

How can I see the SQL query for this call? Assuming I don't have access to database server to profile/monitor the calls, is there way to log or view within my IDE the corresponding SQL queries issued by JPA calls? I'm going against SQL Server 2008 R2 using the jTDS driver.

推荐答案

日志记录选项是特定于提供程序的.您需要知道您使用的是哪种 JPA 实现.

Logging options are provider-specific. You need to know which JPA implementation do you use.

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

  • EclipseLink(参见此处):

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

  • OpenJPA (见这里):

    <property name="openjpa.Log" value="DefaultLevel=WARN,Runtime=INFO,Tool=INFO,SQL=TRACE"/>
    

  • DataNucleus(参见此处):

    将日志类别 DataNucleus.Datastore.Native 设置为一个级别,例如 DEBUG.

    Set the log category DataNucleus.Datastore.Native to a level, like DEBUG.

    这篇关于如何查看JPA发出的SQL查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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