dinesh707
dinesh707

Reputation: 12582

How to get non-distinct results from a hibernate query using "in"

List<Prize> prizes =
                sessionProvider.getCurrentSession().createQuery("from Prize where id in (:ids)")
                        .setParameterList("ids", prizeIds).list();

I have a list of prizeIds, which are not unique. I need to fetch Prize objects for each id. But hibernate returns me only unique elements list. How can i get a list same size as the input list.

Upvotes: 0

Views: 224

Answers (2)

bogdan.herti
bogdan.herti

Reputation: 1107

UPDATE: The thing that you collection has multiple ids changes the things. Certainly Hibernate is doing his job so you must find another solution.

To answear the question properly: It is impossible to get non-distinct results using "in".

Upvotes: 0

Abhijith Nagarajan
Abhijith Nagarajan

Reputation: 4030

The answer you are getting is default functionality of "in" function in database. Use exist or not exist clause to retrieve the records for every id. I doubt whether you can use exist or not exists as well.

But, be sure about the functionality you are trying to achieve, this is not something very common in most of the applications

Upvotes: 1

Related Questions