Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[JPA, TopLink] "Resursive" fetch join

 
Raf Szczypiorski
Ranch Hand
Posts: 383
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Thanks.
 
James Sutherland
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=EclipseLink
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic