-1

Can I give sort parameter not at the end expresion? Because i need use sort parameter inside over() function.

example:

@Query(value = "...?2...over(?4)...?1...?3")
myMethod(int a,int b,int c,Sort sort);

or expression for sort inside over: ,--#sort\n , #{#sort} ..

I still get :

java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.lang.Integer ...name of method.. (int,int,int,org.springframework.data.domain.Sort)!

Victorio
  • 3
  • 1
  • 1
    Did you read the [doc](https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.sorting)? Can you post a [mcve] and complete stacktrace? –  Oct 21 '17 at 08:04

1 Answers1

0

Parameters of type Sort get special treatment by Spring Data JPA.

Even if that wouldn't be the case what you try to achieve can't be accomplished with a simple bind parameter, because bind parameters allowed in these places by SQL.

Depending on what you want to achieve you might be able to do something like the following:

@Query("select .... over(... order by CASE ?1 WHEN "first THEN first
     WHEN 'last' THEN last
     END")
public Something method(String columnNameForSorting)

assuming you have the columns first and last you want to switch between for sorting.

Standard SQL alternative to Oracle DECODE for more information about the CASE expression

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
  • For direct completion string into like (order by ?4) into to the sql, sql returned bad result. But if I tried this way, as you wrote, it was good. Thanks! – Victorio Oct 25 '17 at 07:23
  • If this solves the problem please accept it (click the checkmark) and upvote it. Especially the checkmark makes it obvious to others finding the question what solves the problem. – Jens Schauder Oct 25 '17 at 08:32