2

我正在尝试将分离的条件用作“in”子句的子查询,但不知何故它不起作用:

def trades = new DetachedCriteria(Trade).build {
            projections { property "tradeNbr" }
}

def activities = Activiies.withCriteria {
            'in' "tradeNumber", trades
}

这是我遇到的错误:

2012-11-07 01:07:09,088 [http-bio-8081-exec-1] TRACE sql.BasicBinder  - f228562 - binding parameter [1] as [INTEGER] - grails.gorm.DetachedCriteria@57c4e7b2



grails.gorm.DetachedCriteria cannot be cast to java.lang.Integer. Stacktrace follows:
java.lang.ClassCastException: grails.gorm.DetachedCriteria cannot be cast to java.lang.Integer
            at grails.orm.HibernateCriteriaBuilder.invokeMethod(HibernateCriteriaBuilder.java:1587)
            at org.grails.datastore.gorm.GormStaticApi.withCriteria(GormStaticApi.groovy:282)
4

1 回答 1

2

我相信这list只是一个默认值,因为您可以在each类似的构造中使用它

trades.each {
    println it
}

那是因为它实现了 Iterable。否则,您实际上必须使用trades.list(). 只是 usingtrades指的是 DetachedCriteria 对象。

def activities = Activities.withCriteria {
    'in'("tradeNumber", trades.list())
}
于 2012-11-08T06:49:16.493 回答