-
Notifications
You must be signed in to change notification settings - Fork 936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make ISession.IsDirty() method immutable operation #1413
Comments
Seems related to NH-2727 and NH-2136 which were closed as "Not an issue" without much explanations. |
Maybe some information is in the mailing lists (I’m away sleeping, so could not check now) |
Read the linked issues. I don’t know why this is an “expected behavior”, @fabiomaulo. Could you please elaborate? I agree that the behavior should be as described by @bahusoid. |
I can't remember which was the discussion around this matter... let me check... |
Ok... IIRC things, in these cases, are wired with flush mode. In NH-2727 Ricardo said he is changing the entity during saveorupdate (probably with a listener) so the session becomes dirty. IMO as he have implemented a custom-listener to do something during saveorupdate he should change even DefaultDirtyCheckEventListener. |
The point with identity is, why should About NH-2727, it looks to me as boiling down to this question: is it legit for By the way this issue 1413 is indeed two issues: the many-to-one failure and the id generation triggered by |
Yes Federic, in general terms something called |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
So, it seems that this is the same as NH-2136, except it happens to anything regardless of the type of id generator. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…enerator Depending on the db, an insert may be triggered (SQL-Server) or not (Oracle). Tested with Statistics rather than SqlLogSpy: it avoids parsing the SQL for distinguishing between select (done with Oracle over the sequence) and insert (done with SQL-Server). See nhibernate#1413
Depending on the db, an insert may be triggered (SQL-Server) or not (Oracle). See nhibernate#1413
Есть давно известный баг nhibernate/nhibernate-core#1413 в том что при вызове IsDirty хибернейт может сохранять изменения в базу. Частично это решается открытием транзакции. которая откатывается при отмене. Но если какие то из полей стоят not-null то проблема записи при проверке не исчезает. Поэтому реализована собственная проверка на изменения. Откуда взять код указано в начале класса.
This is actually |
… flush The default cascade for it was SaveUpdate (via base AbstractFlushingEventListener) which triggered insertion of the entities with post-insert style ID generators (eg. identity). Persist on the other hand will make sure that insertion of the entity is delyed until flush is called. Fixes nhibernate#1413
… avoid flushing the session (#2752) The default cascade for it was SaveUpdate (via base AbstractFlushingEventListener) which triggered insertion of the entities with post-insert style ID generators (eg. identity). Persist on the other hand will make sure that insertion of the entity is delayed until flush is called. Related to #1413
Does this happen also in older NHibernate 3.x? I am right now struggling with a huge performance gap after migrate NHibernate from 3.1 to 5.3.16/5.4.2 on calling IsDirty, Since the call is near after every change in program, it lead to a less fluent work flow. |
I am not sure whether this bug applies to such an old version or not, but is sounds likely to me. About the performance loss for your application, if you could pinpoint what causes it (like profiling sql queries and seeing if there are more of them issued on IsDirty calls, or other things), that would help seeing if that is something needing a fix, and then please report it as a new issue with detailed information of how to reproduce it. About the principle of calling frequently IsDirty, that is anyway a huge source of performance loss. The basic mechanism for dirty checking in NHibernate has not changed since its first releases: at worst the session iterates all entities it holds and compares their current state with the state they were having at load time. That is a quite heavy mechanism. |
I will keep that in mind. That I try to make an example in my spare time. I will post at least the profiling result in a new issue. |
No DB modifications but session state is still modified (see #2752 (comment)) |
ISession.IsDirty() method description:
So expected behavior: method should not persist any entities (work in read-only mode)
And current behavior: It's very unexpected that this call can lead to data modifications in DB:
all cascaded entities are saved (at least all with Identity ID lead to DB inserts - very unexpected and dangerous behavior)
Edit: that point is fixed in 5.4 by #2752, but the session state can still be mutated by
IsDirty
: this needs still to be fixed.My use case for using this ISession.IsDirty() is the following:
With current implementation I can't use
IsDirty()
as it will save childentity.Children
elements without transaction context - very dangerous and unexpected.See test case #1414
The text was updated successfully, but these errors were encountered: