基于嵌入式日期字段的Grais列表不起作用

时间:2014-09-23 09:17:22

标签: grails gorm

我是grails的新手,并试图根据Embedded class的日期字段获取Domain列表。

以下工作正常

def res = User.findAll { lt 'createdDateTime', new Date }

def res = User.findAll { eq 'account.name', 'JOHN' }

但是,

def res = User.findAll { lt 'account.createdDateTime', new Date }

以上总是返回空列表。

'帐户' class嵌入到User类

User.groovy

class User {
   String name
   Integer age
   Date ctratedDateTime // test
   Account account
   static embedded = [
      'account'
   ]
}

Account.groovy

class Account {
    String userName
    String password
    Date createdDateTime
}


def res = User.findAll { 
  account{ 
    lt 'createdDateTime', new Date 
  }
}

上面收到以下错误

org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Executing action [list] of controller [com.test.UserController]  caused exception: Runtime error executing action
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:200)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.codehaus.groovy.grails.web.servlet.mvc.exceptions.ControllerExecutionException: Runtime error executing action
... 5 more
Caused by: java.lang.reflect.InvocationTargetException
... 5 more
Caused by: java.lang.NoSuchMethodError: com.test.UserController$_getFilteredForexRates_closure9.<init>(Ljava/lang/Object;Ljava/lang/Object;Lgroovy/lang/Reference;)V
at com.test.UserController$$EOqgV3Um.getFilteredForexRates(UserController.groovy:172)
at com.test.UserController$_closure5$$EOqgV3Um.doCall(UserController.groovy:109)
... 5 more

我是以正确的方式做的吗?请建议我解决的方法。

感谢。

1 个答案:

答案 0 :(得分:2)

你应该使用嵌套闭包:

def res = User.withCriteria{ 
  account{ 
    lt 'createdDateTime', new Date 
  }
}