SpringDataJPA - What does '?1' in the where clause mean in the below query?

992 Views Asked by At
@Query(value="select * from author a where a.last_name= ?1",nativeQuery = true)

What does ?1 mean in the above query?

1

There are 1 best solutions below

1
HittingMyCode On

This ?1 indicate a positional parameters is a different practice for define a query parameters to advoid some issue like SQL injection, for example:

  • Named parameters:
    String statment = "SELECT * from Users WHERE name=:nameParam and role=:roleParam";

    //some code

    query.setString("nameParam", nameValue);

    query.setString("roleParam", roleValue);
  • Positional parameters:
    String statment = "SELECT * from Users WHERE name=?1 and role=?2";
    
    //some code

    query.setString(1, nameValue);

    query.setString(2, roleValue);