문제
나는 Groovy/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.
해결책
직무 관계를 중첩해야합니다 (사용자와 함께 US EQ 만 할 수도 있음) :
def minutes = c.get {
and{
eq("user", user)
job{
between("happening", firstDate, lastDate)
}
}
projections {
sum("minutesWorked")
}
}
건배
이씨
제휴하지 않습니다 StackOverflow