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

标签 grails gorm

我是新手,试图根据嵌入式类的日期字段获取域列表。

以下工作正常

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 }

上面总是返回空列表。

“帐户”类已嵌入到“用户”类中

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

我做的正确吗?请给我建议解决方法。

谢谢。

最佳答案

您应该使用嵌套的闭包:

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

关于grails - 基于嵌入式日期字段的Grais列表不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25991303/

相关文章:

oracle - 域类映射:数据源不起作用

java - 使用 XMLslurper 获取内部数据

xml - JAXB编码没有为这些域对象返回某些值

grails - 我们可以在Grails的服务中获取 Controller 的实例吗

spring - 如何在并发 session 访问中使上一个 session 到期

具有Hasmany字符串的Grails/GORM条件查询

grails - Grails控件联接表

database - 找不到Grails jdbcsqlexception列

grails - Criteria查询中的Grails LazyClob

mysql - groovy grails 构建测试数据(buildtestdata 插件)如何创建多对多