Issue
I'm using Grails 4.0.12, and I'm trying to make an update using IN clause, this is my simple code:
def rowId="100,101"
Image.executeUpdate("update Image set status='DELETED' where status='NEW' and id in (:ids)", [ids: rowId])
If I build the query string like this, everything works:
Image.executeUpdate("update Image set status='DELETED' where status='NEW' and id in ("+ids+")")
While in the fist example I'm getting this error:
java.lang.String cannot be cast to java.lang.Long
Which seems reasonable if I pass just one Id without IN clause.
Solution
Try to correct your first example in the following way:
def rowIds = [100, 101]
Image.executeUpdate("update Image set status='DELETED' where status='NEW' and id in (:ids)", [ids: rowIds])
Answered By - SternK