Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EclipseLink JPQL (Glassfish v3): join fetch syntax problem?

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

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].

(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.

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

I'd appreciate any help!

Rodrigo

like image 809
javabeats Avatar asked Nov 28 '25 08:11

javabeats


1 Answers

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

like image 125
Gordon Yorke Avatar answered Nov 30 '25 00:11

Gordon Yorke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!