Tuesday, July 22, 2014

Grails: CreateCriteria with Projection

Here is an example of using createCriteria() function in grails using projection of sum.

This method returns the sum of Balance in from Finance model/domain.
You can put this code in Bootstrap.groovy to run it when the program starts.

 println Finance.createCriteria().list() {  
                eq('financeType', FinanceTypeEnum.SAVINGS)  
                projections {  
                     sum('balance')  
                }  
           }  


No comments:

Post a Comment