In NH, Criteria was forked long time ago and that is not a bug (unfortunately).
If you want change the behavior you can add a JIRA ticket but, please, remember to give a little mention to the BIG breaking change we will have. On Wed, Dec 22, 2010 at 12:49 PM, SoWeLie <[email protected]> wrote: > Hey Guys, > > I'm not sure if this is a bug or not so I wanted to post here first. > Let me set up a scenario. Say I have three entities, User, Role and > Group. > > User looks like this: > > public class User { > public virtual string Name { get; set; } > public virtual IList<Group> Groups { get; set; } > public virtual IList<Role> Roles { get; set; } > } > > Role looks like this: > > public class Role { > public virtual string Name { get; set; } > } > > Group looks like this: > > public class Group { > public virtual string Name { get; set; } > public virtual IList<Role> Roles { get; set; } > } > > Now, if I execute the following criteria query, some very strange > behavior occurs: > > session.CreateCriteria<User>("u") > .CreateAlias("u.Roles", "r", JoinType.LeftOuterJoin) > .CreateAlias("u.Groups", "g", JoinType.LeftOuterJoin) > .CreateAlias("g.Roles", "gr", JoinType.LeftOuterJoin) > .Add( > Restrictions.Or( > Restrictions.Eq("r.Name", "SomeRole"), > Restrictions.Eq("gr.Name", "SomeRole") > ) > ) > .List<User>(); > > > > What happens is the users returned all have their groups filtered by > the specified criteria. So, all that is in each user's Groups > collection is any groups that have the role specified in the > criteria. As you can see I'm not specifying fetch mode, so it > shouldn't even be loading the Groups collection based on the criteria > query. I tried setting the FetchMode explicitly to Lazy as well as > setting the ResultTransformer explicitly to RootEntity yielding the > same result. > > I have done this before in the Java version of Hibernate and I've > never run into this issue. > > My current work around is to use HQL instead, which does not have this > problem. Is this a known bug? I am I doing something wrong? Should I > file this? Thanks! > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > > -- Fabio Maulo -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
