0

使用 in 子句参数执行 EntityManager 删除本机查询时出现错误。该参数是 List 类型,我想做类似的事情 -

List<UUID> ids = ...
entityManager.createNativeQuery("DELETE FROM FOO WHERE ID IN (:ids)")
        .setParameter("ids", ids)
        .executeUpdate();

我得到的例外是 -

javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: ERROR: IN could not convert type bytea to uuid
  Position: 39
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1377)
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1300)
    at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:1387)
    at org.hibernate.ejb.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:108)
[snip]

请让我知道如何运行上面的删除查询。

4

1 回答 1

0

Since its a Native query you should have something like below: entityManager.createNativeQuery("DELETE FROM FOO WHERE ID IN (?1)") .setParameter(1, ids) .executeUpdate();

Also, I think you don't need native query in this case, below code should work too:

entityManager.createQuery("DELETE FROM FOO WHERE ID IN (:ids)")
    .setParameter("ids", ids)
    .executeUpdate();
于 2013-10-13T01:51:41.283 回答