Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set array of parameters to hibernate query language

Tags:

hibernate

hql

Currently the query takes in a single reportID to return the results. Now if I want to pass multiple reportIDs and return the o/p in just 1 call to the DB, how do I do that?

String queryText = "from com.abc.domain.bcd.Report report  where report.reportID in :reportId";

    Query query = SessionFactory.getCurrentSession().createQuery(queryText.toString());

    query.setParameter("reportID", reportId);

    query.list();

I tried passing as an arrayList but no luck. Got the error below

List<String> reportID= new ArrayList<String>();
    reportID.add("aaa");
    reportID.add("bbb");

java.util.ArrayList incompatible with java.lang.String

like image 629
dazzle Avatar asked Nov 22 '12 11:11

dazzle


1 Answers

try this one

 query.setParameterList("reportID", new Object[]{"aaa","bbb"});
like image 99
rajesh kakawat Avatar answered Oct 05 '22 21:10

rajesh kakawat