If I translate my problem to the example in the book, I'd like to retrieve the 10 most recently created Items together with their bids (in order to display all bids or find out the maximum bid or whatever).
If I implement it like this...
Code:
int numberOfResults = 10;
List results = session.createCriteria(Item.class)
.addOrder(Order.desc("created"))
.setMaxResults(numberOfResults)
.setFetchMode("bids", FetchMode.EAGER)
.list();
...I've got the problem that only 10 non-distinct result sets are returned. If there are 10 Bids for each Item, I'd only get 1 Item after making the results distinct.
Since I don't have any idea how many Bids each Item has, I have to fetch all items. Or am I wrong?
I would wish that Hibernate would somehow do the magic and make the results distinct for me. What's the point of getting non-distinct results anyway? I could formulate statements like "SELECT i, b FROM Item i, Bids b WHERE b.item = i" if I really want a more join-like result.
Regards,
Andreas