Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to express "where value is in dynamic list" in HQL/GORM?

For a grails application, I need to find a list of objects whose "attr" is one in a dynamic list of strings. The actual HQL query is more complex, but the bit I need help with is this:

def result = MyObject.executeQuery("select o from MyObject as o where o.attr in :list",
    [list: aListOfStrings])

This is obviously not the right syntax, Grails throws it back at me as an "unexpected token", being the :list parameter.

Is this possible in HQL? I don't particularly want to use Criteria in this part of the codebase.

like image 838
xcut Avatar asked Jun 07 '10 20:06

xcut


1 Answers

Put :list in parens:

def result = MyObject.executeQuery(
    "select o from MyObject as o where o.attr in (:list)",
    [list: aListOfStrings])
like image 74
Burt Beckwith Avatar answered Nov 16 '22 00:11

Burt Beckwith