I hope someone can help me with using Criteria API to create correct search query. I have many-to-many relationship between Clients and Products. On the search page I have list of all the products,
and when user selects some products, I would like query to return all the clients who have ALL the products selected by the user. For example, on the list we have ProductOne, ProductTwo, ProductThree, and
if the user selects ProductOne and ProductThree, I'd like all the clients who have (among the possible others) ProductOne and ProductThree.
At the moment I have a query which returns clients which have either of the two products, but I want only those who have both.
I understand that 'Restrictions.in' returns true for each given product, but I don't know how to rewrite it and what to used instead in order to return true only if Client has all the given products.
Ben Gateau Jr
posted 11 years ago
Does anyone have any idea how to achieve this? I had high hopes for the Restrictions.conjunction() but it doesn't work well when the same field is used. Any links or recommended books would be appreciated too.