Skip to content

Conversation

csharper2010
Copy link
Contributor

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.

@hazzik
Copy link
Member

hazzik commented May 18, 2012

@csharper2010 could you please provide any test case?

@csharper2010
Copy link
Contributor Author

Test Case added in
NHibernate.Test.Stateless.FetchingLazyCollections.LazyCollectionFetchTests

2012/5/18 Alexander Zaytsev <
[email protected]

@csharper2010 could you please provide any test case?


Reply to this email directly or view it on GitHub:
#111 (comment)

unknown and others added 3 commits August 16, 2012 21:55
Shows that the change made in StatelessSessionImpl.GetEntityUsingInterceptor effectively eliminates Duplicates in a Linq query with Join Fetch.
@csharper2010
Copy link
Contributor Author

I've added a test case now for FetchMany and ThenFetchMany. It's now based on current master.

Message I got from "monkeypro": This change almost seems to solve my problem with stateless session! Execpt if I use FetchMany and ThenFetchMany I still get duplicate instances on the second level.
Since I'm completely new to GitHub (1 day), I don't know how things work with commits and new releases. When can I get a stable version of NHibernate with this fix in it?

@oskarb
Copy link
Member

oskarb commented Sep 21, 2014

I think this corresponds to Hibernate issue https://hibernate.atlassian.net/browse/HHH-2564 which also refers to the initial feature description for stateless sessions: https://hibernate.atlassian.net/browse/HHH-742, which contains this specification (shortened):

Note that the semantics of querying are:

  • all entities and collections joined in the original query are loaded, and uniqueing is done

Issue HHH-2564 isn't fixed, since 2007.

@hazzik
Copy link
Member

hazzik commented Sep 21, 2014

I'm not sure about HQL, but linq should follow linq semantic for sure.

@oskarb
Copy link
Member

oskarb commented Sep 21, 2014

@oskarb
Copy link
Member

oskarb commented Sep 21, 2014

The weirdness (multiple root instances, but sharing the collection instance) I noted in NH-3705 I think indicates that the current behavior is a bug (or possibly unsupport/undefined behavior) (as opposed to this being a feature request).

@oskarb
Copy link
Member

oskarb commented Sep 21, 2014

We already had https://nhibernate.jira.com/browse/NH-3015 apparently.

@oskarb
Copy link
Member

oskarb commented Sep 21, 2014

NH-3015 is marked for 5.0. @hazzik This behavior sounds so buggy to me - do you think we really should hold it until 5.0 or should we do it in 4.1?

@hazzik
Copy link
Member

hazzik commented Sep 21, 2014

Ok, let's do 4.1

But we need to make sure that all similar issues are fixed.

@oskarb
Copy link
Member

oskarb commented Oct 2, 2014

@hazzik Did you have some specific case in mind, or do you just mean we should do more for different scenarios?

@hazzik
Copy link
Member

hazzik commented Oct 2, 2014

@oskarb, no I don't have anything at the moment.

@hazzik hazzik added this to the 4.1.0 milestone Oct 18, 2014
@oskarb oskarb self-assigned this Oct 22, 2014
@oskarb
Copy link
Member

oskarb commented Oct 22, 2014

Rebased and merged in a29dbf8.

@oskarb oskarb closed this Oct 22, 2014
@hazzik hazzik changed the title Stateless Session with deduplicated result with join fetch NH-3015 - Stateless Session with deduplicated result with join fetch Nov 18, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants