title: How to filter a PostgreSQL array column with the JPA Criteria API?
body: <p>I am using:</p>
  
  <ul>
  <li>Hibernate 4.3.5</li>
  <li>Spring JPA 1.6.0</li>
  <li>Javax Persistence API 2.1</li>
  </ul>
  
  <p>The "refcodemailing" column is defined as an array of int: int[]</p>
  
  <p>My entity object:</p>
  
  <pre><code>@Entity
  @Table
  public class CalendarEvent implements Serializable {
  
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id = 0;
  
    @Convert(converter = IntegerArrayConverter.class)
    @Column(name = "refcodemailing")
    private final List&lt;Integer&gt; mailingCodes = new ArrayList&lt;&gt;();
  
    // ....
  
  }
  </code></pre>
  
  <p>I am trying to filter the column array with the following JPA Specification method:</p>
  
  <pre><code>private final List&lt;MailingCode&gt; mailingCodes = new ArrayList&lt;&gt;();
  
  @Override
  public Predicate toPredicate(Root&lt;CalendarEvent&gt; root, CriteriaQuery&lt;?&gt; query, CriteriaBuilder cb) {
  
    // Mailing codes
    if(!mailingCodes.isEmpty()){
      List&lt;Predicate&gt; mailingCodePred = new ArrayList&lt;&gt;();
  
      for(MailingCode mailingCode: mailingCodes){
        restrictions.add(cb.isMember(mailingCode.getId(), root.&lt;List&lt;Integer&gt;&gt;get("mailingCodes")));
      }
  
      restrictions.add(cb.and(cb.isNotNull(root.&lt;List&lt;Integer&gt;&gt;get("mailingCodes")),       cb.or(mailingCodePred.toArray(new Predicate[]{}))));
    }
  }
  </code></pre>
  
  <p>But the following exception is thrown:</p>
  
  <pre><code>java.lang.IllegalArgumentException: unknown collection expression type [org.hibernate.jpa.criteria.path.SingularAttributePath]
      at org.hibernate.jpa.criteria.CriteriaBuilderImpl.isMember(CriteriaBuilderImpl.java:1332)
      at com.agenda.CalendarEventQuery.toPredicate(CalendarEventQuery.java:100)
      at org.springframework.data.jpa.repository.support.SimpleJpaRepository.applySpecificationToCriteria(SimpleJpaRepository.java:521)
      at org.springframework.data.jpa.repository.support.SimpleJpaRepository.getQuery(SimpleJpaRepository.java:472)
  </code></pre>
  
  <p>Is there a way to do it?</p>