如何使用 getTranslatedSQLString 获取 Toplink 生成的查询?
所以我正在做的是创建一个获取 ID 值列表的子查询,然后主查询获取所有必要的值并添加排序。
我所得到的是:
ReportQuery querySub = new ReportQuery(Predmet.class, generatedExpression);
querySub.addAttribute("m_id");
DatabaseRow row = new DatabaseRow();
querySub.prepareCall(getSession(), row);
// This part is the problem
String sql = querySub.getTranslatedSQLString(getSession(), row);
此代码的问题是它不返回 TranslatedSQLString,它返回与 querySub.getSQLString()
相同的结果。现在,在我看到的所有示例代码中,他们要么将 row 实例化为新对象,要么懒得从获得引用的位置进行编写,但无论如何,这都不起作用(TopLink 版本问题?)。我猜我需要自己填充 DatabaseRow 对象,但我在网上找不到任何示例。
So what I'm doing is creating a subquery that gets a list of ID values, then the main query gets all the necessary values and adds ordering.
What I have is this:
ReportQuery querySub = new ReportQuery(Predmet.class, generatedExpression);
querySub.addAttribute("m_id");
DatabaseRow row = new DatabaseRow();
querySub.prepareCall(getSession(), row);
// This part is the problem
String sql = querySub.getTranslatedSQLString(getSession(), row);
The problem with this code is that it doesn't return TranslatedSQLString, it returns the same result as querySub.getSQLString()
. Now in all the example code I saw, they either instanced row as a new object or didn't bother to write from where they got the reference but whatever the case, this doesn't work (TopLink version issue?). I'm guessing I need to populate the DatabaseRow object myself, but I can't find any example online.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有找到任何方法来使用 getTranslatedSQLString 来做到这一点。我想 DatabaseRow 需要填充,但我还没有找到正确的方法。现在,我正在使用“暴力”替换,我“记住”所有参数并对每个“?”进行查找/替换登录查询。
I didn't manage to find any way to do this by using getTranslatedSQLString. I suppose the DatabaseRow needs to be populated, but I have yet to find the proper way. For now, I'm using "bruteforce" substitution, I "memorize" all of my parameters and do a find/replace on each "?" sign in the query.
您需要像这样获得会话:
您需要的数据库是:
所以最后一个例子是:
这对我有用。
you need get session like this:
The Database that you need is:
So the final example is:
That work for me.