EclipseLink JPQL(Glassfish v3):加入获取语法问题? [英] EclipseLink JPQL (Glassfish v3): join fetch syntax problem?

查看:101
本文介绍了EclipseLink JPQL(Glassfish v3):加入获取语法问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Hibernate中,我习惯于执行以下操作:

With Hibernate I'm used to do something like the following:

select n from NetworkElement n join fetch n.site s where s.active is true

但是,EclipseLink对此抱怨很多:

However, EclipseLink complains a lot about this:

Caused by: Exception [EclipseLink-8024] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.JPQLException Exception Description: Syntax error parsing the query [select n from NetworkElement n join fetch n.site s], line 1, column 49: syntax error at [s].

Caused by: Exception [EclipseLink-8024] (Eclipse Persistence Services - 2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.JPQLException Exception Description: Syntax error parsing the query [select n from NetworkElement n join fetch n.site s], line 1, column 49: syntax error at [s].

(堆栈上的查询与上面的查询不同,但结果相同)

(The query on the stack is different from the one above, but the result is the same)

我尝试了不同的组合,但都不起作用:

I've tried different combinations, none of which worked:

select n from NetworkElement n join fetch n.site where n.site.active is true
select n from NetworkElement n join fetch n.site as site where site.active is true

我还尝试在域模型中切换到其他实体,怀疑我的映射不正确.仍然是同样的问题.

I also tried switching to a different entity in my domain model, suspecting that maybe my mapping is not correct. Still, the same problem.

是否只能使用查询提示来实现?我不想那样做.

Could it be that I can only achieve this using a query hint? I don't want to do that.

顺便说一句,我使用的是Netbeans 6.8和Glassfish v3附带的EcliseLink.

By the way, I'm using EcliseLink as shipped with Netbeans 6.8 and Glassfish v3.

我将不胜感激!

Rodrigo

推荐答案

主要问题是JPQL语法不允许别名获取连接,这就是EclipseLink为此功能使用查询提示的原因.有一个增强请求,可以直接在JPQL中添加别名连接获取,如果您希望看到它完成,请投票. ( https://bugs.eclipse.org/bugs/show_bug.cgi?id = 293775 ).

The main issue is that the JPQL syntax does not allow for aliasing fetch joins and that is why EclipseLink uses query hints for this functionality. There is an Enhancement Request to add aliasing join fetches directly in the JPQL and if you would like to see it completed please vote for it. ( https://bugs.eclipse.org/bugs/show_bug.cgi?id=293775 ).

-戈登·约克(Gordon Yorke)

--Gordon Yorke

这篇关于EclipseLink JPQL(Glassfish v3):加入获取语法问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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