将参数数组设置为hibernate查询语言 [英] Set array of parameters to hibernate query language

查看:99
本文介绍了将参数数组设置为hibernate查询语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前查询需要一个reportID来返回结果。现在,如果我想传递多个reportID,并在1次调用DB时返回o / p,那我该如何做?

  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();

我尝试以arrayList传递,但没有运气。

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

java.util.ArrayList与java.lang.String不兼容
<请尝试这一个

  query.setParameterList(reportID)解析方法


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

解决方案

try this one

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

这篇关于将参数数组设置为hibernate查询语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆