gpt4 book ai didi

java - 将列表传递给 in 子句但在 jpql 中不起作用

转载 作者:行者123 更新时间:2023-12-01 12:03:08 27 4
gpt4 key购买 nike

请解决我的问题,我正在尝试运行这些 jpql

代码是这样的

List<Jewellery> jewelleries;
List<Seller> searchedSellers;
List<Integer> jewelleryIds;
jewelleries = entityManager
.createQuery(
"SELECT j FROM Jewellery j WHERE j.id = (SELECT jt.id FROM JewelleryType jt WHERE jt.type = :type)",
Jewellery.class)
.setParameter("type", jewelleryType).getResultList();
for (Jewellery j : jewelleries) {
jewelleryIds.add(j.getId());
}
searchedSellers = entityManager
.createQuery(
"SELECT s FROM Seller s WHERE (s.city.id = (SELECT c.id FROM City c WHERE c.city = :parameter1 )) AND (s.jewellery.id in (:parameter2))",
Seller.class)
.setParameter("parameter1", city)
.setParameter("parameter2", jewelleryIds).getResultList();

我在console.log文件中发现以下错误

java.lang.IllegalArgumentException: You have attempted to set a value of type class java.util.ArrayList for parameter
parameter2 with expected type of class java.lang.Integer from query
string SELECT s FROM Seller s WHERE (s.city.id = (SELECT c.id FROM City c WHERE c.city = :parameter1 )) AND (s.jewellery.id in (:parameter2))

请解决问题。提前致谢..

最佳答案

我认为您的 JPQL 查询无效,您必须删除 IN 子句的括号,例如:

SELECT s FROM Seller s WHERE (s.city.id = (SELECT c.id FROM City c WHERE c.city = :parameter1 )) AND (s.jewellery.id in :parameter2)

关于java - 将列表传递给 in 子句但在 jpql 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27856200/

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