Uploaded image for project: 'Hibernate ORM'
  1. Hibernate ORM
  2. HHH-5419

COUNT operator with composite primary key and JPA 2.0 Criteria API produces bad sql

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.5.4, 3.6.0.Beta1, 4.0.0.CR3
    • Fix Version/s: 4.0.0.CR4, 4.0.0.CR5
    • Component/s: None
    • Labels:
      None
    • Environment:
      hibernate-entitymanager 3.6.0.Beta1, glassfish 3.0.1, linux ubuntu 10.04, MS SQL Server 2008
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Suitable for new contributors:
      Yes, likely
    • Last commented by a user?:
      true

      Description

      Hibernate produces a invalid SQL if anyone use the count() operator with the JPA 2.0 Criteria API. Code:

      CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
      CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);
      Root<EntityCompositePK> r = cq.from(EntityCompositePK.class);

      cq.multiselect(cb.count(r));
      assertEquals(0, ((Long) (getEntityManager().createQuery(cq).getSingleResult())[0]).intValue());

      I'm sending a little maven project which reproduces the bug.

        Attachments

          Issue links

            Activity

              People

              • Votes:
                3 Vote for this issue
                Watchers:
                9 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: