Grails
  1. Grails
  2. GRAILS-7880

Support HAVING criteria on HibernateCriteriaBuilder

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:

      Description

      I would like to be able to write

        def commentsByUserAndArticle = Comment.createCriteria().list {
          projections {
            countDistinct('id', 'commentCount')
            groupProperty('userAccount')
            groupProperty('article')
            having {
             gt('commentCount', 5)
            }
          }
          order('commentCount', 'desc')
        }
      

      Instead, I currently have:

        def commentsByUserAndArticle = Comment.executeQuery(
                  "select count(c.id), c.userAccount, c.article \
                from my.domain.Comment c \
                group by c.userAccount, c.article \
                having count(c.id) > :abuseIndicator \
                order by count(c.id) desc",
                  ["abuseIndicator":5L])
      

      It might be that this isn't supported by Hibernate itself; I'm not that familiar with the codebase, but thought this would be a nice enhancement to the createCriteria functionality.

        Activity

        Hide
        Graeme Rocher added a comment -
        Show
        Graeme Rocher added a comment - Depends on https://hibernate.onjira.com/browse/HHH-1043

          People

          • Assignee:
            Unassigned
            Reporter:
            James Abley
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Last Reviewed:

              Development