title: Bind array param to native query
body: <p>I have table <strong>product_spec_entry</strong> with following columns:</p>
  
  <ul>
  <li>product_spec_id</li>
  <li>commodity_spec_id</li>
  </ul>
  
  <p>for one <strong>product_spec_id</strong> may be several <strong>commodity_spec_id</strong>, for example:</p>
  
  <pre><code>|product_spec_id | commodity_spec_id|
  |----------------|------------------|
  |1683            |1681              |
  |1692            |1693              |
  |1692            |1681              |
  |1692            |1687              |
  |1692            |1864              |
  |1860            |1681              |
  |1868            |1681              |
  |1868            |1864              |
  </code></pre>
  
  <p>I want get all <strong>product_spec_id</strong> that have all <strong>commodity_spec_id</strong> are passed as parameter. </p>
  
  <p>I wrote next query:</p>
  
  <pre><code>SELECT ps.product_spec_id, commodities
  FROM (
         SELECT
           product_spec_id,
           array_agg(commodity_spec_id) AS commodities
         FROM system.product_spec_entry
         GROUP BY product_spec_id) ps
  WHERE Cast(ARRAY [1681, 1864] as BIGINT[]) &lt;@ Cast(ps.commodities as BIGINT[]);
  </code></pre>
  
  <p>It's work fine, and return expected result:</p>
  
  <blockquote>
    <p>product_spec_id = 1692, 1868</p>
  </blockquote>
  
  <p>I try use this query for JPA native query:</p>
  
  <pre><code>String query = "SELECT ps.product_spec_id " +
                  "FROM ( " +
                  "       SELECT " +
                  "         product_spec_id, " +
                  "         array_agg(commodity_spec_id) AS commodities " +
                  "       FROM system.product_spec_entry " +
                  "       GROUP BY product_spec_id) ps " +
                  "WHERE CAST(ARRAY[:commoditySpecIds] AS BIGINT[]) &lt;@ CAST(ps.commodities AS BIGINT[])";
  List&lt;Long&gt; commoditySpecsIds = commoditySpecs.stream().map(Spec::getId).collect(Collectors.toList());
  
  List&lt;BigInteger&gt; productSpecIds = em.createNativeQuery(query).setParameter("commoditySpecIds", commoditySpecsIds)
                  .getResultList();
  </code></pre>
  
  <p>It does not work because I get array of record (<code>ARRAY[(1692, 1868)]</code>) instead array of bigint (<code>ARRAY[1692, 1868]</code>)</p>
  
  <p>How I should bind array param to my query? May be I can use more simple query for it.</p>