【问题标题】:How to replace composite key in select count with JPA criteria如何用 JPA 标准替换选择计数中的复合键
【发布时间】:2012-11-22 23:01:38
【问题描述】:

在hibernateHHH-5419发现这个bug

我需要了解如何将类型的根元素替换为复合键,例如用星号。

更新休眠,使用 JPQL 不是答案。

【问题讨论】:

    标签: hibernate jpa jpa-2.0


    【解决方案1】:

    没关系。 用它替换了复合键的查询:

        CriteriaBuilder qb = entityManager.getCriteriaBuilder();
        CriteriaQuery<Long> cq = qb.createQuery(Long.class);
        Root<T> root = cq.from(entityClass);
        if (root.getModel().getIdType() != null)
            cq.select(qb.count(root.get("someAnotherAttribute")));
        else
            cq.select(qb.count(root));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 2014-07-29
      • 2018-08-22
      • 2016-05-31
      • 2012-08-16
      • 1970-01-01
      • 2011-11-11
      相关资源
      最近更新 更多