繁体   English   中英

使用In Query在JPA中的参数中添加2个列表

[英]Add 2 list in parameter in JPA using In Query

我想使用IN查询带有元组的JPA查询中传递两个列表

例如。 select custid from employee where (custid,name) in ((1,"ford"),(3,"eli"))

这是正常的查询,并且有效,但是这里我有清单和名称,所以我想使用IN Query传递列表。

查询是

String sql="select employee.custid from Employee employee

where (employee.id.custid,employee.id.name)  IN (  (:listofcustid , :listofname ))";

我将参数设置为

    Query query = em.createQuery(sql); 
    query.setParameter("listofcustid", custidlist);
    query.setParameter("listofname", namelist);

但是它不起作用并且给出例外

    unexpected AST node: {vector} 
[ select employee.custid from com.dao.Employee  employee where 
(employee.id.custid,employee.id.name)  IN 
((:custIdList0_, :custIdList1_, :custIdList2_),(:nameList0_, :nameList1_, :nameList2_))]

但是对于单个列表,它工作正常

  String sql="select employee.custid from Employee employee

    where employee.id.custid IN ( :listofcustid )";

query.setParameter("listofcustid",listofcustid);

当我尝试移除内牙套

( :listofcustid , :listofname )

它给出了带有(),?,?,?,?,?)中参数的完整精确查询的输出,

这意味着它不将其作为元组,其次是异常和以下行

" ORA-00920: invalid relational operator "

难道不应该是这样吗? (为每个命名参数打开和关闭括号)

String sql="select employee.custid from Employee employee

where (employee.id.custid,employee.id.name)  IN ((:listofcustid) , (:listofname ))";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM