我有一个产品 ID 列表,我想通过 hibernate 查询从我的数据库中获取所有产品。我该怎么做?
List<Integer> list = custumor.getCart();
Query query = query("select product from Product product where product.id =: list");
我知道这不是解决此问题的最佳方法,但我只想知道如何测试列表中的所有值。
最佳答案
您需要做两件事...第一是将您的 HQL 更改为以下内容(使用 IN),第二是绑定(bind)您的参数列表:
Query query = query("select product from Product product where product.id IN :list")
.setParameterList("list", list);
关于java - 从 hibernate 列表中选择所有项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6360931/