title: CriteriaBuilder Predicate IN
body: <p>Something went wrong with this code. I try to create a custom query but I get always the same error.</p>
  
  <pre><code>public class Photo {
      @Id 
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      private Long photoId;
      private String title;
  
  
      @ManyToMany
      @JoinTable(name="PHOTO_THEME",
              joinColumns=@JoinColumn(name="PHOTO_FK"),
              inverseJoinColumns=@JoinColumn(name="THEME_FK"),
              uniqueConstraints=@UniqueConstraint(columnNames= {"PHOTO_FK", "THEME_FK"}))
      @JsonManagedReference
      private List&lt;Theme&gt; themes;
  
  }
  </code></pre>
  
  <p>Here my class Theme</p>
  
  <pre><code> public class Theme {
  
          @Id
          @GeneratedValue(strategy=GenerationType.IDENTITY)
          private Long themeId;
  
          @Lob
          @Column(length=1000000)
          private String description;
  
          @JsonBackReference
          @ManyToMany(mappedBy="themes")
          private List&lt;Photo&gt; photos;
  
  
          @Override
          public String toString() {
              return "Theme [themeId=" + themeId + "]";
          }
  
  
      }
  </code></pre>
  
  <p>My repository</p>
  
  <pre><code>    public interface IPhotoRepository extends JpaRepository&lt;Photo, Long&gt;, 
                        JpaSpecificationExecutor&lt;Photo&gt;{
  }
  </code></pre>
  
  <p>My service</p>
  
  <pre><code>@Service
  public class PhotoServiceImpl implements IPhotoService {
      @Autowired
      private IPhotoRepository photoRepository;
      @Autowired
      private ThemeServiceImpl themeService;
  
  
      @Override
      public List&lt;Photo&gt; findByCriteria(PhotoFilters filter) {
          return this.photoRepository.findAll(new Specification&lt;Photo&gt;() {
  
              @Override
              public Predicate toPredicate(Root&lt;Photo&gt; root, CriteriaQuery&lt;?&gt; query, CriteriaBuilder criteriaBuilder) {
                  List&lt;Predicate&gt; predicates = new ArrayList&lt;&gt;();
  
  
                  if (filter.getTheme() != null &amp;&amp; filter.getTheme() != "") {
  
                      Theme themex2 = themeService.findByType("Retro");
                      List&lt;Theme&gt; listThemes = new ArrayList&lt;Theme&gt;();
                      listThemes.add(themex2);
  
                      In&lt;Theme&gt; predicate = criteriaBuilder.in(root.get("themes"));
  
                      listThemes.forEach(t -&gt; predicate.value(t));
  
                      predicates.add(predicate);
                  }
                  return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
              }
          });
      }
  
  }
  </code></pre>
  
  <p>And This is the ERROR:</p>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException: Parameter value [Theme
    [themeId=1]] did not match expected type [java.util.Collection (n/a)]
      at
    org.hibernate.query.spi.QueryParameterBindingValidator.validate(QueryParameterBindingValidator.java:54)
    ~[hibernate-core-5.4.1.Final.jar:5.4.1.Final] ...</p>
  </blockquote>