java - Pass list of values on query parameter -


string hql = "select * mytable isactive in (:isactive)";         query query = session.createquery(hql);         query.setstring("school","");         query.setstring("isactive", "y");//working         query.setstring("isactive", "n");//working         query.setstring("isactive", "y","n"); // not working         query.setstring("isactive", "'y','n'"); // not working         return query.list(); 

i have no idea if code below should work, wondering if can pass list of values search string parameter there's no need me create queries ; 1 select data regardless of status , select active data.

use query.setparameterlist() pass in list parameter:

string hql = "select * mytable isactive in (:isactive)"; query query = session.createquery(hql); list<string> isactivelist = new arraylist<>(); isactivelist.add("y"); isactivelist.add("n"); query.setparameterlist("isactive", isactivelist); return query.list(); 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -