Question

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?

Was it helpful?

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top