如何查看JPA发出的SQL查询? [英] How to view the SQL queries issued by JPA?
问题描述
当我的代码发出如下调用时:
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.
-
Hibernate(见这里):
<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屋!