0
我是新來的Groovy/Grails的,而我試圖做一個標準的搜索是找出所有帖子一個月,基本上是這樣的:選擇從一個月中的所有事件的Grails
def getUserMinutesForYear(User user, Date date){
Date firstDate = new GregorianCalendar(date.year, Calendar.JANUARY, 1, 0, 0, 0).time
Date lastDate = new GregorianCalendar(date.year, Calendar.DECEMBER, 31, 23, 59, 59).time
def c = JobRegistration.createCriteria()
def minutes = c.get {
and{
eq("user.id", user.id)
between("job.happening", firstDate, lastDate)
}
projections {
sum("minutesWorked")
}
}
return minutes
}
的域類是
class Job {
String title
String description
Date happening
static hasMany = [registrations:JobRegistration]
}
class User {
static hasMany = [authorities: Role, registrations: JobRegistration]
static belongsTo = Role
String username
}
class JobRegistration {
Job job
User user
Integer minutesWorked
static belongsTo = [user:User,job:Job]
static constraints = {
user(blank: false)
job(blank:false)
minutesWorked(nullable :true)
}
String toString(){
return user.userRealName
}
}
現在,爲什麼我會得到此異常?
org.codehaus.groovy.runtime.InvokerInvocationException:org.hibernate.QueryException:無法解析屬性:的job.happening:JobRegistration
這很有效。第一個讓我困惑的是,像 eq(「user.id」,user.id) 這樣的工作,雖然它沒有爲job.happening工作。在事後看來,我可以看到user.id可能被表示爲一個基本的int,而job.happening是一個對象。 – 2009-09-25 09:40:43