File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes [JPA, TopLink] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "[JPA, TopLink] "Resursive" fetch join" Watch "[JPA, TopLink] "Resursive" fetch join" New topic

[JPA, TopLink] "Resursive" fetch join

Raf Szczypiorski
Ranch Hand

Joined: Aug 21, 2008
Posts: 383
Hi. I am currently learning EJB3, and time has come to get the hang of JPQL. I have two persistence units, one uses TopLink Essentials (default for GlassFish, the application server I am using), and the other one is Hibernate EntityManager.
I hava a Category class, that has a one-to-many mapping to itself. That is, a Category has a parent, and a category has many subcategories. With Hibernate, it is possible to "recursively" fetch parents. For example, Category A has a Subcategory B, which has Subcategory C. This query returns the whole hierarchy starting with C, going upward:

I can also use

which TopLink refuses to process even for one fetch join, as there is an alias specified for the fetch property.
So my question is, can this be done in Toplink? Or is it one limitation of JPA altogether, to allow only one level of fetch joins?
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
The JPA 1.0 JPQL specification does not allow an alias or nested fetch joins.

TopLink Essentials, or at least EclipseLink (Glassfish v3) support nested fetch joins through a query hint "eclipselink.join-fetch".

Feel free to log an enhancement request for the JPQL extension for EclipseLink on Bugzilla.

TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
I agree. Here's the link:
subject: [JPA, TopLink] "Resursive" fetch join
It's not a secret anymore!