JPA Native Query delete in

delete-row, jpa, native

Solution

One way that works is if you not use the id value like you tried, but instead use the entity and let JPA handle the identification of it like this:

HashSet<Transaction> transactions = new HashSet<Transaction>();
... 
entityManager.createQuery(
  "DELETE FROM Transaction e WHERE e IN (:transactions)").
  setParameter("transactions", new ArrayList<Transaction>(
  transactions)).executeUpdate();

Hope it helps you in the right direction.

Problem

I try to delete a list of rows from a table using this Native Query: ``` @NamedNativeQuery(name="WebGroup.DeleteIn", query="DELETE FROM WebGroup WHERE WebGroup.GROUP_ID IN (:IDsList)" getEm().createNamedQuery("WebGroup.DeleteIn") .setParameter("IDsList", groupToDeleteIDs) .executeUpdate(); ``` and this is the SQL that MySQL executes: ``` DELETE FROM WebGroup WHERE WebGroup.GROUP_ID IN (:IDsList) ``` SO, JPA doesn't replace the variable IDsList... Some one could help me please?

Original source