You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using @Query in a JPA repository along with Pageable and attempting to sort on a field in a joined fetch entity, the from entity gets prepended to the sort field. Because the alias got a bad result. For example, if I do the following query:
@Query(value = "SELECT DISTINCT user FROM User user LEFT JOIN FETCH user.authorities authority")
if I simply decide to sort by a field in the Authority entity with this PageRequest:
Jean Philippe Emond opened DATAJPA-1000 and commented
When using
@Query
in a JPA repository along with Pageable and attempting to sort on a field in a joined fetch entity, the from entity gets prepended to the sort field. Because the alias got a bad result. For example, if I do the following query:if I simply decide to sort by a field in the Authority entity with this PageRequest:
The query run is:
And I got :
Normal because authorities is property of User not authority
But If I remove the FETCH
With the same PageRequest, my query run is:
Perfect!
I look a bit on the code of org.springframework.data.jpa.repository.query.QueryUtils
for method getOuterJoinAliases
The FETCH put the mess with the QUERY_JOIN_ALIAS_GROUP_INDEX
Affects: 1.10.4 (Hopper SR4)
Referenced from: commits 3bba394, f765602, 6fedc49
Backported to: 1.10.6 (Hopper SR6), 1.9.7 (Gosling SR7)
The text was updated successfully, but these errors were encountered: