Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data and Native Query with Sorting

In a web project, using spring-data(1.10.4.RELEASE) with a Oracle database, i am trying use a native query with a Sort variable.

public interface UserRepository extends JpaRepository<User, Long> {
  @Query(nativeQuery = true,value = "SELECT * FROM USERS WHERE LASTNAME = :lastname #sort")
  List<User> findByLastname(@Param("lastname") String lastname, Sort sort);
}

The query launched is:

SELECT * FROM USERS WHERE LASTNAME = 'Lorite' #sort ORDER BY LASTNAME

Like you can see the annotation "#sort" is still there.

I have tried Spring Data and Native Query with pagination but the annotation is there yet and using another syntax like ?#{#sort} or {#sort} the problem persist.

Anything is welcome.

Thanks!

like image 336
Dlorite Avatar asked Oct 26 '16 11:10

Dlorite


1 Answers

The documentation says:

Note, that we currently don’t support execution of dynamic sorting for native queries as we’d have to manipulate the actual query declared and we cannot do this reliably for native SQL.

Furthermore, this #sort interpolation does not exist

[1] http://docs.spring.io/spring-data/jpa/docs/current/reference/html/

like image 144
Lucas Oliveira Avatar answered Oct 03 '22 20:10

Lucas Oliveira