【问题标题】:java.lang.IllegalArgumentException: Update/delete queries cannot be typedjava.lang.IllegalArgumentException:无法键入更新/删除查询
【发布时间】:2021-11-08 18:21:58
【问题描述】:

我想创建用于删除行的 SQL 查询。我试过这个:

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();
}

但我得到了例外: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 您知道发送要删除的 Id 列表的正确方法是什么吗?

【问题讨论】:

标签: java spring spring-boot spring-data-jpa spring-data


【解决方案1】:

TypedQuery&lt;X&gt; 是产生X 类型的返回对象或其列表的查询。 更新和删除查询不会返回任何内容,因此您必须为它们使用不同类型的查询。

使用EntityManager.createQuery(String) 而不是EntityManager.createQuery(String, Class) 应该可以解决问题。

【讨论】:

    猜你喜欢
    • 2021-07-01
    • 2015-07-13
    • 1970-01-01
    • 2015-04-10
    • 1970-01-01
    • 2014-08-17
    • 1970-01-01
    • 1970-01-01
    • 2011-11-27
    相关资源
    最近更新 更多