Join fetch with Stateless Session returns duplicate entities

Description

I've created a patch and a pull request for this: https://github.com/nhibernate/nhibernate-core/pull/50

I was experimenting a little with the stateless session. I found that when eager fetching entities like this...
using (var session =
sessionFactory.OpenStatelessSession())
using (var transaction = session.BeginTransaction())
{
var list = session.Query<Order>()
.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.

Environment

None

Activity

Alex Zaytsev 
May 1, 2017 at 3:42 AM

Closing issues resolved in 4.1.0

Oskar Berggren 
October 22, 2014 at 8:26 PM

Fix merged in a29dbf8ea40764ac0895cd96e7fcd9b92f7eab26.

Oskar Berggren 
September 21, 2014 at 9:56 PM

Reported with some additional info before discovering this one.

CSharper2010 
October 20, 2013 at 3:49 PM

Fixed

Details

Assignee

Reporter

Labels

Components

Fix versions

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created January 13, 2012 at 9:03 PM
Updated May 1, 2017 at 3:42 AM
Resolved October 22, 2014 at 8:26 PM
Who's Looking?