Deleted Entity Appears in Query Results

9 views
Skip to first unread message

Tim Scott

unread,
Jul 29, 2011, 12:28:34 PM7/29/11
to nhusers
I delete a given entity, and later in the same session I query using
criteria that matches that entity. Despite that it's been deleted,
the entity appears in the results. Is that expected NH behavior? I
am "fixing" it this problem by calling Flush immediately after the
delete. It seems wrong to force a flush to prevent deleted entities
from appearing in queries. Is there some other way to handle this
scenareo? (BTW: I tried Persist. I think that is not meant for
deleted entities, because it threw.)

Jason Meckley

unread,
Jul 29, 2011, 1:20:35 PM7/29/11
to nhu...@googlegroups.com
yes, this makes sense given the concept and structure of a unit of work and identity map, which is the session. use a session for either reads or writes, not both.

Richard Brown (gmail)

unread,
Jul 30, 2011, 4:13:20 AM7/30/11
to nhusers
I would expect that to work as long as:

1. You are in an NH transaction;
2. The FlushMode is Auto.

--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
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.

Jason Meckley

unread,
Jul 30, 2011, 9:40:20 AM7/30/11
to nhu...@googlegroups.com
flushing only occurs after the transaction is committed, not when you call save/delete. these types of methods only add commands to the queue. when the session is flushed the commands are executed.

Richard Brown (gmail)

unread,
Jul 30, 2011, 11:04:38 AM7/30/11
to nhu...@googlegroups.com
The FlushMode has three (sensible) options:
 
Never:  The developer flushes themselves;
Commit:  Flush will only occur at transaction commit;
Auto:  NH will flush as required.
 
I believe when you are in a transaction, and use FlushMode.Auto (the default), each query will examine the tables it uses, and if that intersects with any of the tables used in the pending unit-of-work, it will issue a flush first.
 
I would expect the query in Tim’s example to cause an automatic flush if the FlushMode is Auto and inside an NH transaction (notwithstanding we haven’t seen the code or mappings).
--
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/-/uRspTHNg5XoJ.
Reply all
Reply to author
Forward
0 new messages