JPA本机查询是否允许对多个条件使用一个Set Parameter

时间:2018-04-01 07:55:52

标签: hibernate jpa jpql

以下是我的示例脚本。

getEntityManager()
.createNativeQuery("select * from TABLE1 T1, TABLE2 T2 where T1.DEPARTMENT_ID = :departmentId and T2.DEPARTMENT_ID = :departmentId") 
.setParameter("departmentId",departmentId) 
.getResultList();

提前致谢

2 个答案:

答案 0 :(得分:1)

这是可能的,在我的情况下,我有以下查询原生为我工作,

entityManager.createNativeQuery("select i.customer_customerid, c.name 
from Invoice i inner join Customer c on c.customerid = i.customer_customerid 
where c.customerid=:id and i.invoicenumber=:id")
.setParameter("id",  1l)
.getResultList();

答案 1 :(得分:0)

我不知道是否允许,但您可以将查询更改为:

getEntityManager()
.createNativeQuery("select * from TABLE1 T1, TABLE2 T2 where T1.DEPARTMENT_ID = T2.DEPARTMENT_ID  and T2.DEPARTMENT_ID = :departmentId") 
.setParameter("departmentId",departmentId) 
.getResultList();