title: Grails: Adding sorting and paging to a custom HQL query
body: <p>I have a list method that uses HQL. how do I add the paging and sorting parameters to this query?  </p>
  
  <pre><code>   def list = {
           def termList
          log.info "Getting terms for product: $params.productId"
          params.max = 10
          def p = Product.get(params.productId)
          if (p) {
              log.info "Product found: $p.name"
              termList = Term.executeQuery("select distinct t from Term as t join t.definitions def join def.definitionProducts dp where dp.product=?",
                  p )
  
          } else {
              log.info "No Product found"
              termList = Term.list(params)
  
          }
          log.info "Terms found: $termList.size"
  
          [ termInstanceList: termList, termInstanceTotal: termList.size]
      }
  </code></pre>