title: How to delete items by ID-s of their child item in Hibernate?
body: <p>I'm trying to write an JPQL query which would delete all <code>PlaylistItem</code>-s refering to specific <code>ArtContent</code>-s by <code>ArtContent</code> IDs.  </p>
  
  <p>I tried this:</p>
  
  <pre><code>public int deleteItemsByContentIds(Long[] contentIds) {
      EntityManager em = getEntityManager();
      int result = em.createQuery(
      "delete from PlaylistItem where artContent.id in (:idsArray) ")
      .setParameter("idsArray", contentIds).executeUpdate();
  
      return result;
  }
  </code></pre>
  
  <p>but it throws an exception:</p>
  
  <pre><code>Servlet.service() for servlet RemoveContentServlet threw exception: 
  javax.ejb.EJBException: java.lang.IllegalArgumentException: 
  Encountered array-valued parameter binding, but was expecting [java.lang.Long]
  </code></pre>
  
  <p>What is understandable, because there is no <code>setParameter</code> method taking an array as an argument. So what is the best way to solve such an issue?</p>
  
  <p>Simplified class definition:</p>
  
  <pre><code>@Entity
  public class PlaylistItem implements Serializable {
  
  @Id
  @GeneratedValue
  private Long id;
  
  private int position;
  
  @ManyToOne(optional = false)
  @JoinColumn(name = "PLAYLIST_ID")
  private Playlist playlist;
  
  @ManyToOne(optional = false)
  @JoinColumn(name = "ART_CONTENT_ID")
  private ArtContent artContent;
  
  ...
  </code></pre>
  
  <p>}</p>
  
  <pre><code>@Entity
  public class ArtContent implements Serializable {
  
  @Id
  @GeneratedValue
  private Long id;
  ...
  }
  </code></pre>