2
我想傳遞兩個列表中JPA查詢與使用元組在查詢參數使用添加2列表JPA查詢
爲如。 select custid from employee where (custid,name) in ((1,"ford"),(3,"eli"))
這是正常的查詢,它的工作原理,但在這裏我有custid和名稱的列表,所以我想通過列表使用IN查詢。
查詢是
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 "
爲什麼不使用「where employee.id.custid in:listofcustid和employee.id.name in:listofname」? –
這是不高效的,否則我們已經使用OR也 – anshulkatta
@IgorRodriguez:這將是一個不同的查詢。第一個相當於'where(custid = 1和name ='ford')或(custid = 3和name ='eli')',而你的相當於'where(custid = 1或custid = 3)和(name ='ford'或name ='eli')' –