Domanda

I am trying to use a detached criteria as subquery for 'in' clause but somehow it does not work:

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

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

This is the error that I am running into:

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)
È stato utile?

Soluzione

I believe that list is only a default in the sense that you can use it in an each construct like

trades.each {
    println it
}

And that's because it implements Iterable. Otherwise you actually have to run the query with trades.list(). Just using trades refers to the DetachedCriteria object.

def activities = Activities.withCriteria {
    'in'("tradeNumber", trades.list())
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top