pieterk
pieterk

Reputation: 295

Possible to pass a Map object to HQL

Is it possible to pass a whole map object to a HQL query without iterating over it? I would if I have to but thought there might be a cleaner way.

For example:

def aMap = ["foo":"bar", "bar":"foo"]

Foo.executeQuery("select p from p where p.bar in (:mapObj)", [mapObj: aMap])

Then have it automatically uses the key on the aMap?

If I try it it just throws this error:

Remember that ordinal parameters are 1-based!

Upvotes: 1

Views: 787

Answers (1)

Victor Sergienko
Victor Sergienko

Reputation: 13475

That cryptic error says executeQuery() just expects a different Map as a last parameter - with a different data type or key names.

No, it won't automatically use Map's keys. If it ever did, I'd suppose that it should use values() instead. Anyway, it would be counter-intuitive.

So just use aMap.keySet(), it is about the absolute minimum of overhead you can get from Map.

Upvotes: 2

Related Questions