How to set formula in grails domain class?

grails, grails-2.0, grails-domain-class, grails-orm, grails-services

Solution

You need to make these fields non transient to use in criteria. See reference document

http://gorm.grails.org/6.1.x/hibernate/manual/#derivedProperties

Problem

I am trying to write formula in my domain class which helps me in creating criteria. ``` class MyClass { //some fields Date appointmentTime String ddmmyy int year int month int day static transients = [ 'ddmmyy', 'year', 'month', 'day' ] static mapping= { ddmmyy formula('DATE_FORMAT(appointmentTime)') year formula('YEAR(appointmentTime)') month formula('MONTH(appointmentTime)') day formula('DAYOFMONTH(appointmentTime)') } } ``` Whenever I am trying to use this fields in my criteria it throws error i.e. can not resolve property 'ddmmyy' of 'myClass'. MyCriteria is: ``` Date myDate = Calender.instance.time def results = MyClass.createcriteria().list{ lt('appointmentTime', date+1) ge('appointmentTime', date) projections { groupProperty('ddmmyy') count('id') } } ``` Any idea why I am getting an exception for this?

Original source