NiBE
NiBE

Reputation: 927

Update record with clause IN

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.

Upvotes: 0

Views: 39

Answers (1)

SternK
SternK

Reputation: 13041

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])

Upvotes: 1

Related Questions