Set array of parameters to hibernate query language

穿精又带淫゛_ 提交于 2019-12-30 04:35:06

问题


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


回答1:


try this one

 query.setParameterList("reportID", new Object[]{"aaa","bbb"});


来源:https://stackoverflow.com/questions/13512109/set-array-of-parameters-to-hibernate-query-language

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!