This content has been marked as final. Show 2 replies
JPA does not allow alias names on fetch joins, I suspect partially because they could then be used in the filtering in the query - which is exactly what you are doing. This could cause potential caching issues, as the entity that is built might end up missing references that don't conform to the conditions in the where clause, as discussed here:
According to bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=293775 this has been changed and is supported in EclipseLink 2.4 to some degree.
If you cannot use EclipseLink 2.4 or later, the way to do this in JPQL is to use a separate join for the alias to be used in the query, and one for the fetch join.
"SELECT DISTINCT g FROM GUI g "
+ "JOIN FETCH g.gUINameAllocation "
+ "JOIN FETCH g.elementAllocation "
+ "JOIN g.gUINameAllocation gna "
+ "JOIN g.elementAllocation gea "
+ "JOIN gea.elementTextAllocation geta "
+ "WHERE g.gUIID = " + java.lang.Integer.toString(GUI) + " "
+ "AND gna.languageAllocation.languageID = " + java.lang.Integer.toString(Language)
+ "AND geta.languageAllocation.languageID = " + java.lang.Integer.toString(Language);
Unfortunately JPA does not allow nested fetch joins, so the only way to fecth gea.elementTextAllocation is through a query hint:
EclipseLink/TopLink's join-fetch query hint is described here: