【问题标题】:Get current object ID in Generic DAO. Hibernate在通用 DAO 中获取当前对象 ID。休眠
【发布时间】:2013-11-10 18:14:36
【问题描述】:

我想在 Hibernate Generic Dao 实现中按 ID 删除所有对象。

现在我创建了这样的方法:

  @Override
    public void deleteByIds(Collection<Serializable> ids) {
        getSession()
                .createQuery("delete from " + getDomainClass() + " where id in (:ids)")
                .setParameter("ids", ids)
                .executeUpdate();
    }

但查询中的id 属性未定义。这意味着我只能在使用@NamedQueries 的实体上使用此方法,并且无法将此方法提取到通用 DAO?

【问题讨论】:

    标签: java hibernate hibernate-generic-dao


    【解决方案1】:

    假设id 在您的休眠实体中可用,您需要更改

    setParameter("ids", ids)
    

    setParameterList("ids", ids)
    

    【讨论】:

      猜你喜欢
      • 2014-10-23
      • 2012-04-01
      • 1970-01-01
      • 2014-12-20
      • 2023-03-16
      • 2017-11-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多