Search code examples
grailshibernate-criteria

How to fix an hibernate criteria datepart error?


I have a domain with a calculated field.

durationInMinutes formula: 'datepart(minute, Duration) + datepart(hour, Duration) * 60'

and use it in a createCriteria

property('durationInMinutes')

but this generates an error in the logfile

java.sql.SQLException: 'this_.minute' is not a recognized datepart option.

Please help. I use MySQL.

Found this working solution:

projections {
    sqlProjection '(datepart(minute, Duration) + datepart(hour, Duration) * 60) as TimeInMinutes', 'TimeInMinutes', INTEGER

Solution

  • I am using the MySQL database, but I think it is a hibernate releated question?