Tracking entity saved/transient with stateless sessions (chapter 21.4 from the reference documentation)

17 views
Skip to first unread message

pvginkel

unread,
Jun 13, 2012, 2:00:14 AM6/13/12
to nhu...@googlegroups.com
I've implemented the example from chapter 21.4 from the reference documentation (see  http://nhforge.org/doc/nh/en/index.html#example-parentchild-update) which explains how you can track whether an entity is transient by implementing an interceptor. However, stateless sessions don't go through interceptors, so this doesn't work for entities that are loaded through a stateless session.

Is there a work around/solution to this problem?

Anne Epstein

unread,
Jun 13, 2012, 8:41:35 AM6/13/12
to nhu...@googlegroups.com
My gut feeling would be that I highly doubt it if you want to stay stateless.  The  idea of stateless sessions is very lightweight sessions that don't have tracking (they don't have very much of anything, to the point of being a little difficult to use if you're used to regular sessions) - this is why they are faster- less stuff to manage. Stateless sessions tend to be much more manual to work with for this reason. Honestly, I personally find the only reason to use them is for speed/memory issues in targeted hot spots of an application, and if you are hitting those kinds of problems, you should also at least consider the possibility of optimizing those specific operations by yanking them out of NHibernate entirely and into raw sql-it'll be much, much faster at really big bulk operations than NHibernate can ever be.

On Wed, Jun 13, 2012 at 1:00 AM, pvginkel <pvgi...@gmail.com> wrote:
I've implemented the example from chapter 21.4 from the reference documentation (see  http://nhforge.org/doc/nh/en/index.html#example-parentchild-update) which explains how you can track whether an entity is transient by implementing an interceptor. However, stateless sessions don't go through interceptors, so this doesn't work for entities that are loaded through a stateless session.

Is there a work around/solution to this problem?

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/tW5MSHa_Yn8J.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.

Pieter van Ginkel

unread,
Jun 13, 2012, 8:52:23 AM6/13/12
to nhu...@googlegroups.com
The thing is: the reference documentation states that this should work. However, going with the approach from the reference documentation just falls apart in stateless sessions without any kind of work around (because you're disabling normal transient tracking).

Still I think there should be an option to get this to work. If I'm correct, loading is performed in TwoPhaseLoad.InitializeEntity and it gives at least a IPersistenceContext (SetEntryStatus) and IEntityPersister (AfterInitialize) a chance to perform extra actions on the entity. It seems that I can't take control over the IPersistenceContext and using IEntityPersister would become very cumbersome because I would have to define persisters for all types of existing persisters and specify them in the schema.

If I'm missing an option, suggestions are very welcome.
Reply all
Reply to author
Forward
0 new messages