gpt4 book ai didi

从列表中选择 JPA

转载 作者:行者123 更新时间:2023-12-04 20:47:26 25 4
gpt4 key购买 nike

我似乎无法运行这个简单的查询。我有一个 id 列表,我想从 db 中检索所有具有此 id 的行。

 List<String> uniqueIds is my list.

我试过 String q = "SELECT item FROM Tenant item WHERE item.id IN (:"+uniqueIds+")";
我也试过这个没有:和()。他们都没有工作。我究竟做错了什么。我也尝试了(字符串唯一标识:唯一标识){
在 += uniqueId + ",";
}

并且也使用了“in”!

谢谢。

最佳答案

您应该将参数绑定(bind)到查询。参数是匿名的( ? )或命名的( :parameterName ):

TypedQuery<Tenant> query = 
em.createQuery("select item from Tenant item where item.id in :ids", Tenant.class);
query.setParameter("ids", uniqueIds);
List<Tenant> result = query.getResultList();

关于从列表中选择 JPA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12484844/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com