0

I have a list of Products (Products is id, name, price etc.). The products are referred to by id (not linked in the hibernate xml) in another table reporting.

I want to have a method that will receive a list of products and then take those products and generate a where x in (productlist). My hql looks like this:

SELECT category, SUM(id.downloadTrackingCount) " +
"FROM Reporting " +
"WHERE (id.productId IN (:products)) AND (id.fullDownloadDate BETWEEN :startDate AND :endDate) " +
"GROUP BY category";

But when I try to setParameter on the productlist I get an error saying cannot cast Products to Integer. Is there some method that I can use that will tell Hibernate to do a getId on each product in the list and then fill that in for the :products parameter?

1 Answer 1

2

I think that your best bet is to walk over product list and collect id values into separate list to use as a parameter. Note that you will need to consider corner cases such as empty list and list with more entries that IN clause can handle.

Sign up to request clarification or add additional context in comments.

2 Comments

That is what I thought, I was just hoping beyond hope.
It's probably not that bad :) IN can take only that many items so you will have pretty small number of iterations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.