Hi Fabio
Thanks for the reply. I did think of using the stateless session and
this something I will do at a later stage. I just want to work out why
this is not working and I think I maybe a bit more closer to finding
out why.
When OnPostUpdate method is called, after my entity changes and the
corresponding commit, the linq command is executed and NHibernate
internally wraps a transaction around this, because we have not
explicitly supplied one. Before the linq call we are currently still
within a transaction scope. After NHibernate executes the call,
successfully, NHibernate then internally calls commit which in turn
calls the registered handlers and hence begins our recursion. I have
attached the call stack below which shows this.
I was hoping you could shed some more light on this.
Kind regards
Shahab
dukaan.Data.DLL!
dukaan.Data.SolrNetMaps.SolrListener.OnPostInsert(NHibernate.Event.PostInsertEvent
event) Line 33 C#
NHibernate.DLL!
NHibernate.Action.EntityInsertAction.PostCommitInsert() + 0x25f bytes
NHibernate.DLL!
NHibernate.Action.EntityInsertAction.AfterTransactionCompletion(bool
success) + 0x57a bytes
NHibernate.DLL!
NHibernate.Engine.ActionQueue.AfterTransactionCompletion(bool success)
+ 0x1a1 bytes
NHibernate.DLL!
NHibernate.Impl.SessionImpl.AfterTransactionCompletion(bool success,
NHibernate.ITransaction tx) + 0x26e bytes
NHibernate.DLL!
NHibernate.AdoNet.ConnectionManager.AfterNonTransactionalQuery(bool
success) + 0xaa bytes
NHibernate.DLL!
NHibernate.Impl.AbstractSessionImpl.AfterOperation(bool success) +
0xfc bytes
NHibernate.DLL!
NHibernate.Impl.SessionImpl.List(NHibernate.Impl.CriteriaImpl
criteria, System.Collections.IList results) + 0x4f4 bytes
NHibernate.DLL!
NHibernate.Impl.CriteriaImpl.List(System.Collections.IList results) +
0x71 bytes
NHibernate.DLL!NHibernate.Impl.CriteriaImpl.List() + 0x68 bytes
NHibernate.Linq.DLL!
NHibernate.Linq.CriteriaResultReader<dukaan.Core.Product>.List() +
0x5e bytes
NHibernate.Linq.DLL!
NHibernate.Linq.CriteriaResultReader<dukaan.Core.Product>.GetEnumerator.MoveNext()
+ 0xb9 bytes
mscorlib.dll!
System.Collections.Generic.List<System.__Canon>.List(System.Collections.Generic.IEnumerable<System.__Canon>
collection) + 0x242 bytes
System.Core.dll!
System.Linq.Enumerable.ToList<System.__Canon>(System.Collections.Generic.IEnumerable<System.__Canon>
source) + 0x4a bytes
This is where the linq call happens and I think internally the
NHibernate wraps the call in a transaction which is committed and
hence the handlers are fired again.
dukaan.Data.DLL!
dukaan.Data.SolrNetMaps.SolrListener.OnPostUpdate(NHibernate.Event.PostUpdateEvent
event) Line 44 + 0x44 bytes C#
After my entity changes and the commit of the outer transaction.
NHibernate.DLL!
NHibernate.Action.EntityUpdateAction.PostCommitUpdate() + 0x28f bytes
NHibernate.DLL!
NHibernate.Action.EntityUpdateAction.AfterTransactionCompletion(bool
success) + 0x66a bytes
NHibernate.DLL!
NHibernate.Engine.ActionQueue.AfterTransactionCompletion(bool success)
+ 0x1a1 bytes
NHibernate.DLL!
NHibernate.Impl.SessionImpl.AfterTransactionCompletion(bool success,
NHibernate.ITransaction tx) + 0x26e bytes
NHibernate.DLL!
NHibernate.Transaction.AdoTransaction.AfterTransactionCompletion(bool
successful) + 0xda bytes
NHibernate.DLL!NHibernate.Transaction.AdoTransaction.Commit() +
0x2b3 bytes
On Aug 7, 5:25 pm, Fabio Maulo <[email protected]> wrote:
> You may have some other problems there... btw you can load what you need
> using session.GetSession(EntityMode.Poco) or, even better, a
> stateless-session.
>
> On Sat, Aug 7, 2010 at 5:05 AM, dezzy <[email protected]>wrote:
>
>
>
>
>
> > Hi all,
>
> > I have hooked into NHibernate event model such that, when a entity is
> > updated and committed it cause my listener class, which implements
> > IPostUpdateEventListener, to be instantiated and the OnPostUpdate
> > method to be called. This works fine and is being called the correct
> > number of times and I do what I need to do.
>
> > The problem arises when I use PostUpdateEvent.Session to read from the
> > database. It is a simple Linq to NHibernate call which returns all
> > the products. The list of products is very small, just 5 products, and
> > this code is running in a test using a SqlLite file database.
>
> > public void OnPostUpdate(PostUpdateEvent @event)
> > {
> > var result = @event.Session.Linq<Product>().ToList();
> > }
>
> > This Linq to NHibernate call causes the OnPostUpdate to be called and
> > hence this is the start of our recursive process which naturally leads
> > to a stack overflow exception. I can't understand why OnPostUpdate is
> > being called again. I am assuming that this should only be doing a
> > read-only operation as these event handlers are being called after a
> > commit when all the data have been pushed into the database. Any
> > ideas, or suggestion would be gratefully received.
>
> > Kind regards
>
> > Shahab
>
> > --
> > 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.