Hibernate version:
2.1
Name and version of the database you are using:
MySQL 4.0
Hello everyone,
I'd like to know why Hibernate does not return distinct results if I (eager) fetch a collection.
Please have a look at following code:
(I'm sorry I left out the mapping document, but it should be trivial: 1 user can be assigned 0..n roles. "user.name" is the identity property of a User)
Criteria criteria = session.createCriteria(User.class);
criteria.add(Expression.eq("name", userName).ignoreCase());
criteria.setFetchMode("userRoles", FetchMode.EAGER);
Would you really expect criteria.list() to return a list of identical users, one for each role that is associated to a user?
I am certainly naive, but do I expect too much from O/R-mapping when I'd like Hibernate to shield me from the artifacts of relational joins?
If I really wanted some product of User and Role, I could formulate something like "select User u, Role r where u = r.user"
Regards,
Andreas
|