title: Spring JPA: could not extract ResultSet, ERROR: syntax error at or near "{"
body: <p>I am trying to retrieve a list of paginated data, with @query</p>
  
  <pre><code>@Query(value = "SELECT * FROM message WHERE id IN( SELECT max(id) FROM  message WHERE receiver = ?1 OR sender = ?2  group by receiver,sender) AND (receiver = ?1 OR sender= ?2) #{#pageable}",
          nativeQuery = true)
  
  Page&lt;Message&gt;  findDistinctMessages(User sender, User receiver, Pageable pageable);
  </code></pre>
  
  <p>but i keep getting an error when I call the method:</p>
  
  <pre><code>    11:57:43 [thread] WARN  o.h.e.jdbc.spi.SqlExceptionHelper -SQL Error: 0, SQLState: 42601
  2018-06-18 11:57:43 [thread] ERROR o.h.e.jdbc.spi.SqlExceptionHelper -ERROR: syntax error at or near "{"
    Position: 162
  2018-06-18 11:57:43 [thread] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] -Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause
  org.postgresql.util.PSQLException: ERROR: syntax error at or near "{"
    Position: 162
      at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2455)
      at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2155)
  </code></pre>
  
  <p>This is my Message class</p>
  
  <pre><code>   @Entity
  @Table(name = "Message")
  public class Message extends DefaultEntity {
  
  
      @Valid
      @ManyToOne(targetEntity = User.class)
      @JoinColumn(name="sender")
      private User sender;
  
      @Valid
      @ManyToOne(targetEntity = User.class)
      @JoinColumn(name="receiver")
      private User receiver;
  
  
      @NotNull
      private String message;
  
      @Enumerated(EnumType.STRING)
      private MessageStatus messageStatus;
  
      private Boolean isRead;
  }
  </code></pre>
  
  <p>I have searched for answers, but to no avail, Please what could be the issue.</p>