Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Join fetch with Stateless Session
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
CSharper  
View profile  
 More options Dec 31 2011, 1:20 am
From: CSharper <csharper2...@googlemail.com>
Date: Fri, 30 Dec 2011 22:20:24 -0800 (PST)
Local: Sat, Dec 31 2011 1:20 am
Subject: Join fetch with Stateless Session
Hi,

I was experimenting a little with the stateless session and the next
SQL Server version (will follow in a separate post).

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.

As I am not experienced yet with the development process, I just post
the patch and somebody can tell me what to do or take on the hands on
his/her own. Is somebody interested in following that patch?

The patch in StatelessSessionImpl.cs is as follows:
@@ -449,11 +449,17 @@ namespace NHibernate.Impl
                }

                public override object GetEntityUsingInterceptor(EntityKey key)
                {
                        CheckAndUpdateSessionStatus();
-                       return null;
+            // while a pending Query we should use existing temporary
entities so a join fetch does not create multiple instances
+            // of the same parent item
+            object obj;
+            if
(temporaryPersistenceContext.EntitiesByKey.TryGetValue(key, out obj))
+                return obj;
+            else
+                           return null;
                }

                public override IPersistenceContext PersistenceContext
                {
                        get { return temporaryPersistenceContext; }


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
CSharper  
View profile  
 More options Jan 10 2012, 3:20 pm
From: CSharper <csharper2...@googlemail.com>
Date: Tue, 10 Jan 2012 12:20:49 -0800 (PST)
Local: Tues, Jan 10 2012 3:20 pm
Subject: Re: Join fetch with Stateless Session
I've now created a pull request for this change:
https://github.com/nhibernate/nhibernate-core/pull/50

On 31 Dez. 2011, 07:20, CSharper <csharper2...@googlemail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
CSharper  
View profile  
 More options Feb 16 2012, 4:25 pm
From: CSharper <csharper2...@googlemail.com>
Date: Thu, 16 Feb 2012 13:25:32 -0800 (PST)
Local: Thurs, Feb 16 2012 4:25 pm
Subject: Re: Join fetch with Stateless Session
Anybody using the Stateless Session? I see that change as a quick win.

I don't complain about the lack of feedback on this post but I am just
curious if a remarkable amount of NHibernate developers use the
Stateless Session and for which use cases it is used.
Is it usually only used for write-only actions?
How do people deal with situations where multiple related entity
classes should be read? (I think the join fetch is ideal for many
cases, isn't it?) Are result transformers used in this case to build
the distinct root entity list?

On 10 Jan., 21:20, CSharper <csharper2...@googlemail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rory Plaire  
View profile  
 More options Feb 16 2012, 5:21 pm
From: Rory Plaire <codekai...@gmail.com>
Date: Thu, 16 Feb 2012 14:21:51 -0800
Local: Thurs, Feb 16 2012 5:21 pm
Subject: Re: [nhibernate-development] Re: Join fetch with Stateless Session

I use it, but only for importing data.

In the cases where I need to lookup existing data in order to make
relationships, I have to perform extra queries to get that data, or in some
cases, I persist it in caches so I don't have to round trip back to the
database. But outside of this, the stateless session is way too limited for
normal querying and fetching related entities, as it should be, since it's
main function is to get a lot of data into the database quickly and without
using all the memory.

-r

On Thu, Feb 16, 2012 at 1:25 PM, CSharper <csharper2...@googlemail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »