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

查看:1718
本文介绍了如何查看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。本机到一个级别,比如 DEBUG

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

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

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