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

Grouping by entity does not work for some dialects

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects versions: 5.2.7
    • Fix versions: None
    • Components: hibernate-core
    • Labels:
      None
    • Environment:
      SQL Server 2012
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      Description

      Server which does not support columns in the select list if not contained in the "group by" clause, fail when grouping by entity.

      For example, this fails on SQL Server 2012 (but succeed in H2):

      CriteriaBuilder cb = entityManager.getCriteriaBuilder();
      CriteriaQuery<Tuple> cq = cb.createTupleQuery();
      Root<Foo> foo = cq.from(Foo.class);
      Path<Bar> bar = foo.get("bar");
      cq.multiselect(bar, cb.count(foo));
      cq.groupBy(bar);
      entityManager.createQuery(cq).getResultList();
      

      The generated query is:

      select
          foo0_.[bar_id] as col_0_0_,
          count(foo0_.[id]) as col_1_0_,
          bar1_.[id] as id1_0_,
          bar1_.[name] as name2_0_
      from
          [dbo].[Foo] foo0_
      inner join
          [dbo].[Bar] bar1_
              on foo0_.[bar_id]=bar1_.[id]
      group by
          foo0_.[bar_id]
      

      which fails with this error:

      Column 'dbo.Bar.id' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

      In H2 the same query doesn't fail, because it supports additional columns in the select list if those columns are known to be "dependent" on the grouped ones.

        Attachments

          Issue links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                heruan Giovanni Lovato
                Participants:
              • Votes:
                1 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated: