Search code examples
grailscriteriahibernate-criteria

How can I do an order by desc in createCriteria?


I'm getting a list of the data that I have stored in my column 'age'. What I want to do is to do an order by desc, but I have no idea how I can do it.

My code:

def c = Config.createCriteria()
def checkAge = c.list  {
    projections {                    
        property('age')
    }
}

Solution

  • def c = Config.createCriteria()
    def checkAge = c.list  {
       projections {                    
           property('age')
       }
       order 'age', 'desc'
    }
    

    Refer createCriteria for details.