Alex Rivera | Logout

Select all items from a list in hibernate

Asked 2011-06-15T16:19:51.587
12

I have a list of product ids and I want to get all the products from my db with a hibernate query. How can I do this?

List<Integer> list = custumor.getCart();
Query query = query("select product from Product product where product.id =: list");

I know this isn't the best way to solve this, but I just want to know how I can test for all the values in a list.

Edit
Report

1 Answer

22

There are two things you'll need to do... The first is to change your HQL to the following (making use of IN), and the second is to bind your parameter list:

Query query = query("select product from Product product where product.id IN :list")
    .setParameterList("list", list);
answered 2011-06-15T16:27:57.253

Your Answer