Search code examples
grails-ormhql

GORM findAll + cannot pass dynamic List as named parameter


I am getting the following exception at the following HQL.

java.util.ArrayList cannot be cast to java.lang.String.

Obviously I'm missing something but can't, can't figure it out. Can somebody please advise?

def methodA(List<String> key1List, List<String> key2List){
   def results = DomainX.findAll("from DomainX x where (x.key1 in (:key1_s)) and (x.key2 in (:key2_s))",[key1_s:key1List, key2_s:key2List])
}

The following works but not the above one:

def methodA(List<String> key1List, List<String> key2List){
   def results = DomainX.findAll("from DomainX x where (x.key1 in (:key1_s)) and (x.key2 in (:key2_s))",[key1_s:['ABC'], key2_s:['DEF']])
}

Solution

  • It was my mistake. key2List was like [[key2_a], [key2_b]]; GORM was expecting this to be a flattened list [key2_a, key2_b].