Glassfish Eclipselink join-fetch 提示不起作用
我很难让 eclipselink.join-fetch 提示在 glassfish 中工作。
我有一个 Client 对象,其中包含 Task 对象的集合,而 Task 对象具有 WorkPeriod 对象的集合。
我的代码如下所示:
Query query = entityManager.createQuery("select client from Client client left join fetch client.tasks");
//Set hint to allow nested fetch joins
query.setHint("eclipselink.join-fetch","client.tasks.workPeriods");
List<Client> clients = query.getResultList();
但是,当我将 TOPLINK 调试级别设置为fine 时,无论我做什么,它总是显示实际运行的 SQL 是:
SELECT t0.ID, t0.NAME, t1.ID, t1.DESCRIPTION FROM CLIENT t0 LEFT OUTER JOIN (CLIENT_TASK t2 JOIN TASK t1 ON (t1.ID = t2.tasks_ID)) ON (t2.Client_ID = t0.ID)
显然没有执行连接获取的第三层。
有其他人遇到这个问题吗...或者只是我:-(
任何帮助或提示(没有双关语)将不胜感激。
I'm having real difficulty getting the eclipselink.join-fetch hint to work in glassfish.
I have a Client object that contains a collection of Task objects and the Task object has a collection of WorkPeriod objects.
My code looks like this:
Query query = entityManager.createQuery("select client from Client client left join fetch client.tasks");
//Set hint to allow nested fetch joins
query.setHint("eclipselink.join-fetch","client.tasks.workPeriods");
List<Client> clients = query.getResultList();
But no matter what I do when I set the TOPLINK debug level to fine it always shows that the SQL which is actually run is:
SELECT t0.ID, t0.NAME, t1.ID, t1.DESCRIPTION FROM CLIENT t0 LEFT OUTER JOIN (CLIENT_TASK t2 JOIN TASK t1 ON (t1.ID = t2.tasks_ID)) ON (t2.Client_ID = t0.ID)
Clearly not doing the third tier of the join fetch.
Has anyone else had problems with this... or is it just me :-(
Any help or hints (no pun intended) would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,经过 8 个小时的沮丧之后,我已经找到了真相。
Glassfish V2 不使用 EclipseLink 作为其持久性提供程序,而是使用 Toplink Essentials。 不幸的是,Toplink Essentials 没有提供 join-fetch 提示(我对以下链接感到非常困惑,这让我认为它确实提供了: https://glassfish.dev.java.net/issues/show_bug.cgi?id=1200 虽然这显然是一个功能请求而不是一个功能)。
因此,看来我尝试做的事情是不可能的,如果我想在 glassfish 中进行多级急切获取,我将必须获取 EntityManagers 委托并直接使用 toplink Essentials 表达式。
OK, after 8 hours of frustration I've got to the bottom of it.
Glassfish V2 doesn't use EclipseLink as it's persistence provider, it uses Toplink Essentitals. Unfortunately Toplink essentials doesn't provide a join-fetch hint (I was very confused by the following link which made me think it did: https://glassfish.dev.java.net/issues/show_bug.cgi?id=1200 although this is obviously a feature request NOT a feature).
So it would appear that what I'm attempting to do is not possible and if I want to do multi-level eager fetch in glassfish I'm going to have to get the EntityManagers delegate and use the toplink essentials Expressions directly.