如何发送发送对象的数组到需要的&QUOT一个NamedQuery; ID"所有的对象。 [英] How to send send an array of objects to a NamedQuery that needs the "id" of all the objects.

查看:100
本文介绍了如何发送发送对象的数组到需要的&QUOT一个NamedQuery; ID"所有的对象。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立在JSP页面从穆蒂选表单元素接收到的信息的报告。

在我的仓库类我正在从元素对象的数组。我需要调用这些对象中的每一个的getId 函数,并把这些ID发送到 NamedQuery

下面是一个code例子来帮助解释。我知道如何处理一个单一的对象,但与我得到的 .setParameter(1,员工[]的getId())部分失去对象的数组。

 公开名单< RequestByRequester> getFormInformation(
        员工[]员工)
        抛出NoDataFoundException {        清单< RequestByRequester> resultList = getEm()。createNamedQuery(
                requestByRequestor.getRequestsByRequesters,RequestByRequester.class)
                .setParameter(1,员工[]的getId())
                .getResultList();        返回resultList;
    }

按要求查询:

  SELECT EMP.EMPL_FIRST_NAME || ''|| EMP.EMPL_LAST_NAME REQUESTER,
           R.RQST_ID RQST_ID,
           R.TITLE TITLE,
           R.DESCRIPTION DESCR,
           DE code(R.RESOLUTION_DATE,NULL,打开,关闭)STAT
   从TARTS.REQUESTS R,SYS_EMPLOYEES EMP
  WHERE R.EMPL_ID_REQUESTED_BY = EMP.EMPL_ID
    与EMP.EMPL_ID IN(?)
  ORDER BY 1,5 DESC,2


解决方案

我试着打电话奥秘夫人获得与找出你的查询实际上是帮助,但没有运气,所以我只是要为它去..

您命名查询应该是这个样子:

 选择[x]
从MyClass的点¯x
其中x.children.id(:IDS)

然后让你的ID添加到列表中。

 列表<整数GT; IDS =新的ArrayList<整数GT;();
ids.add(someid); //等

然后使用这个在查询中指定它

  .setParameter(IDS入侵检测系统)

I am building a report from information received from a muti-select form element in a jsp page.

In my repository class I am getting an array of objects from that element. I need to call the getId function for each one of these objects and send those ids to the NamedQuery.

Here is a code example to help explain. I know how to handle a single object but with an array of objects I get lost at the .setParameter(1, employees[].getId()) part.

    public List<RequestByRequester> getFormInformation(
        Employee[] employees) 
        throws NoDataFoundException {

        List<RequestByRequester> resultList = getEm().createNamedQuery(
                "requestByRequestor.getRequestsByRequesters", RequestByRequester.class)
                .setParameter(1, employees[].getId())
                .getResultList();

        return resultList;
    }

By request the query:

    SELECT EMP.EMPL_FIRST_NAME || ' ' || EMP.EMPL_LAST_NAME REQUESTER,
           R.RQST_ID RQST_ID,
           R.TITLE TITLE,
           R.DESCRIPTION DESCR,
           DECODE(R.RESOLUTION_DATE, NULL, 'Open', 'Closed') STAT
   FROM TARTS.REQUESTS R, SYS_EMPLOYEES EMP
  WHERE R.EMPL_ID_REQUESTED_BY = EMP.EMPL_ID
    AND EMP.EMPL_ID IN (?)
  ORDER BY 1, 5 DESC, 2

解决方案

I tried calling Madame Mystique to get help with finding out what your query actually was, but no luck, so I'm just going to go for it...

Your named query should look something like this:

select x
from MyClass x
where x.children.id in (:ids)

then get your ids into a list

List<Integer> ids = new ArrayList<Integer>();
ids.add(someid);  // etc

then use this to specify it in your query

.setParameter("ids", ids)

这篇关于如何发送发送对象的数组到需要的&QUOT一个NamedQuery; ID&QUOT;所有的对象。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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