java.lang.IllegalArgumentException: Update/delete queries cannot be typed

I want to create SQL query for deleting rows. I tried this:

public void deleteByIds(List<Integer> ids)
{
        String hql = "delete from " + OnboardingTasks.class.getName() + " e WHERE e.id IN :ids";
        TypedQuery<OnboardingTasks> query = entityManager.createQuery(hql, OnboardingTasks.class).setParameter("ids", ids);
        query.executeUpdate();
}

But I get exception: ption [Request processing failed; nested exception is java.lang.IllegalArgumentException: Update/delete queries cannot be typed] with root cause java.lang.IllegalArgumentException: Update/delete queries cannot be typed Do you know what is the proper way to send a list of Id’s to delete?

Answer

A TypedQuery<X> is a query that yields a return object of the type X or a list thereof. Update and delete queries don’t return anything, so you have to use a different type of query for them.

Using EntityManager.createQuery(String) instead of EntityManager.createQuery(String, Class) should do the trick.