2

我想使用 IN 查询在 jpa 查询中通过元组传递两个列表

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

这是正常的查询,它可以工作,但这里我有 custid 和 name 的列表,所以我想使用 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_))]

但是对于单个 List 它工作正常

  String sql="select employee.custid from Employee employee

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

query.setParameter("listofcustid",listofcustid);

当我尝试移除内括号时

( :listofcustid , :listofname )

它使用 (? , ? , ? , ? , ? , ?) 中的参数给出整个精确查询的输出,

这意味着它没有将其视为 tuple ,然后是异常和以下行

" ORA-00920: invalid relational operator "

4

1 回答 1

0

不应该是这样的吗?(每个命名参数的左括号和右括号)

String sql="select employee.custid from Employee employee

where (employee.id.custid,employee.id.name)  IN ((:listofcustid) , (:listofname ))";
于 2013-06-28T12:10:06.357 回答