nhibernate/nhibernate-core — pull request #50 by csharper2010 (2012-01-10 20:06:34+00:00)
Title: Join fetch with Stateless Session

See thread on Google Group
http://groups.google.com/group/nhibernate-development/browse_thread/thread/39596596dcb44679

I found that when eager fetching entities like this...
using (var session =
sessionFactory.OpenStatelessSession())
using (var transaction = session.BeginTransaction())
{
var list = session.Query()
.FetchMany(a => a.OrderLines)
.ThenFetch(p => p.Product).ToList();
Assert.AreEqual(2, list.Count(a => a.OrderLines
.Any(p => p.Product.Name.Contains("soft"))));
}

... I get too many aggregate roots in the result, there are duplicate
instances for the same entity. For the stateless session it might be
even more important that the join fetch works as expected because lazy
loading is disabled for it.

With a small modification that would be fixed without the need to use
some result transformers. The stateless session uses a temporary
stateful persistence context and while a Query we could use its
already loaded entities to maintain the object identity thus
deduplicating the result. After the query is finished, the persistence
context is cleared so there is side effect for later queries. I've run
the NHibernate.Test unit tests and they work fine except for those
that have been red on my machine before the change.