[英]How to set formula in grails domain class?
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 ie can not resolve property 'ddmmyy' of 'myClass'. 每当我尝试在我的条件中使用此字段时,它都会引发错误,即无法解析“ myClass”的属性“ ddmmyy”。
MyCriteria is: MyCriteria是:
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? 知道我为什么要为此例外吗?
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 http://gorm.grails.org/6.1.x/hibernate/manual/#derivedProperties
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.