Próbuję napisać zapytanie JPQL, które usunie wszystkie PlaylistItem
-s odnoszące się do określonych ArtContent
-s przez ArtContent
identyfikatorów.Jak usunąć elementy według identyfikatorów ich elementów potomnych w Hibernacja?
Próbowałem to:
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;
}
ale zgłasza wyjątek:
Servlet.service() for servlet RemoveContentServlet threw exception:
javax.ejb.EJBException: java.lang.IllegalArgumentException:
Encountered array-valued parameter binding, but was expecting [java.lang.Long]
Co jest zrozumiałe, ponieważ nie ma setParameter
metoda podejmowania tablicę jako argument. Jaki jest najlepszy sposób rozwiązania tego problemu?
uproszczona definicja klasy:
@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;
...
}
@Entity
public class ArtContent implements Serializable {
@Id
@GeneratedValue
private Long id;
...
}
To wszystko! Wielkie dzięki! – Anke
Działa również dla mnie, dzięki! – kospol