本文介绍了如何从JPQLQuery获取SQL字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用EclipseLink。
I'm using EclipseLink.
我有一个JPQLquery,我想获取sql字符串。.
现在我正在做方式:
I've a JPQLquery and I want to get the sql String..Now I'm doing in this way:
EJBQueryImpl qi = (EJBQueryImpl)jpqlQuery;
String sqlQueryString = qi.getDatabaseQuery().getSQLString();
问题在于,在sqlQueryString中,常量被替换为?
The problem is that in the sqlQueryString the constant are replaced with ?
我尝试获取导航表达式树的值( getSelectionCriteria()
和 getHavingCriteria()
),但我以这种方式丢失了类型...
I've tried to get the values navigating the expressions trees (getSelectionCriteria()
and getHavingCriteria()
) but in this way I loose the type...
有人遇到这样的问题吗?
Do any one ever have a problem like this one?
推荐答案
引自:
要在
运行时获取特定查询的SQL,可以使用DatabaseQuery
API。
To get the SQL for a specific Query at runtime you can use the DatabaseQuery API.
Session session = em.unwrap(JpaEntityManager.class).getActiveSession();
DatabaseQuery databaseQuery = ((EJBQueryImpl)query).getDatabaseQuery();
databaseQuery.prepareCall(session, new DatabaseRecord());
String sqlString = databaseQuery.getSQLString();
Session session = em.unwrap(JpaEntityManager.class).getActiveSession();
DatabaseQuery databaseQuery = ((EJBQueryImpl)query).getDatabaseQuery();
String sqlString = databaseQuery.getTranslatedSQLString(session, recordWithValues);
这篇关于如何从JPQLQuery获取SQL字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!