-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Fetching collections and returning (non-)distinct results
PostPosted: Fri Oct 29, 2004 11:15 am 
Regular
Regular

Joined: Tue Jan 06, 2004 3:32 pm
Posts: 80
Location: Munich, Germany
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.