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

passing list to in clause but not work in jpql

请解决我正在尝试运行这些 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)