Grails

Using aliases in aggregate functions of criteria queries

When using criteria queries, many times we encounter a use case where we need to order our result not on any field of domain class but on our result set, in these cases aliases can be used. In my project, use case was to find most liked products from the domain: [java] ProductStat{ Date dateCreated Product product } [/java] ...

by Puneet Behl
Tag: criteria query
13-Feb-2012

Grails

Alphanumeric Sorting using Criteria Query (with MySQL database)

I am working on a Grails application with MySQL database. I had a use case in which I had to implement alphanumeric sorting using Criteria Query on Grails. By alphanumeric sorting I mean if there is a class Employee with field empId then on doing : [plain] Employee e1 = new Employee(empId:'emp10').save() Employee e2 = new...

by Gaurav Sharma
Tag: criteria query
02-Feb-2012

Grails

Grails criteria query example for unidirectional one-to-many relationships

Following is an example of unidirectional one-to-many relationship: class Employee { String name static hasMany = [roles: Role] } class Role { String name } How can we find all the employees with a particular role - "Grails Developer"? Role role = Role.findByName("Grails Developer") One way of doing...

by Aman Aggarwal
Tag: criteria query
14-Jun-2010