title: How do I use spring data jpa to query jsonb column?
body: <p>I'm having a problem getting this native query right against a postgres 9.4 instance.</p>
  
  <p>My repository has a method:</p>
  
  <pre><code> @Query(value = "SELECT t.* " +
              "FROM my_table t " +
              "WHERE t.field_1 = ?1 " +
              "AND t.field_2 = 1 " +
              "AND t.field_3 IN ?2 " +
              "AND t.jsonb_field #&gt;&gt; '{key,subkey}' = ?3",
              nativeQuery = true)
      List&lt;Entity&gt; getEntities(String field1Value,
                                     Collection&lt;Integer&gt; field3Values,
                                     String jsonbFieldValue);
  </code></pre>
  
  <p>But the logs show this:</p>
  
  <pre><code>SELECT t.* FROM my_table t 
  WHERE t.field_1 = ?1 
    AND t.field_2 = 1 
    AND t.field_3 IN ?2 
    AND t.jsonb_field ? '{key,subkey}' = ?3
  </code></pre>
  
  <p>And I get this exception:</p>
  
  <blockquote>
    <p>Internal Exception: org.postgresql.util.PSQLException: No value
    specified for parameter 2.</p>
  </blockquote>
  
  <p>I logged the parameters directly before method invocation, and they are all supplied.</p>
  
  <p>I'm not sure why <code>#&gt;&gt;</code> shows <code>?</code> in the log. Do I need to escape <code>#&gt;&gt;</code>? Do I need to format the collection for <code>IN</code>? Do I need to escape the json path? </p>
  
  <p>When I execute the query directly against the db, it works. Example:</p>
  
  <pre><code>SELECT *
  FROM my_table t
  WHERE t.field_1 = 'xxxx'
    AND t.field_2 = 1
    AND t.field_3 IN (13)
    AND t.jsonb_field #&gt;&gt; '{key,subkey}' = 'value'
  </code></pre>