我可以从JPA查询对象获取SQL字符串吗? [英] Can I get the SQL string from a JPA query object?

查看:374
本文介绍了我可以从JPA查询对象获取SQL字符串吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以知道如何从JPA查询中获取sql吗?还是说,将JPA查询转换为SQL字符串?非常感谢你!

May I know how can I get the sql from a JPA query? or let's say, convert the JPA query to a SQL string? Thank you very much!

推荐答案

如果只想知道JPQL或Criteria Query如何转换为数据库的SQL方言,则可以在 persistence中启用细粒度的日志记录xml ,然后查看您的日志文件.

If you only want to know how your JPQL or Criteria Query gets translated to the SQL dialect of your database you can enable fine grained logging in the persistence xml and then look into your log files.

属性名称和值取决于您的JPA实现.这是 persistence.xml 的EclipseLink相关部分的示例:

The property name and value depends on your JPA implementation. Here is an example of the relevant part of persistence.xml for EclipseLink:

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

这篇关于我可以从JPA查询对象获取SQL字符串吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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