Skip to content
Auto-generate HQL query based on DSL in domain classes
Java Groovy
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Auto-generate HQL query based on DSL in domain classes


Definition of domain class:

class Author {
    String name
    String lastName
    Date birthday

    static searchFields = [
        fields : [
        defaultField : 'name', //default filter field
        defaultSort : 'name'

Example of use in action "list":

def list(Integer max) {
    params.max = Math.min(max ?: 10, 100)
    params.sort = 'name'
    params.order = 'asc'
    params.field = 'lastName'
    params.value = 'test'

    def search = Author.createSearch()
    search.setSort(params.sort, params.order == 'asc')
    search = search.execute(params.field, params.value)

    //generate: select count(author) from Author author where (lower(author.lastName) like 'test%)
    def count = Author.executeQuery(search.count)

    //generate: from Author author where(lower(author.lastName) like 'test%') order by asc
    def list = Author.findAll(search.query, [max: params.max, offset: params.offset])

    [authorInstanceList: list, authorInstanceTotal: count]
Something went wrong with that request. Please try again.