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.downloadTrackingCo开发者_JS百科unt) " +
"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?
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.
精彩评论