nhibernate-envers icon indicating copy to clipboard operation
nhibernate-envers copied to clipboard

Unexpected session flush when calling AuditReader.GetCurrentRevision

Open akonit opened this issue 6 years ago • 5 comments

This is an illustration for the issue: https://github.com/nhibernate/nhibernate-envers/issues/20

akonit avatar Jul 26 '19 15:07 akonit

DefaultRevisionEntity is behind the scenes mapped as a normal nhib entity with Id mapped with identity generator. When using identity as id generator, this is the behavior AFAIK => when entity is inserted (which it is at the time GetCurrentRevision(true) is called), a flush of the session will be forced.

It might help if you use a custom revision entity where Id is using generator HiLo or something else but identity. Haven't tried this myself though.

If identity generator is used in revision entity mapping (as default), this is something that needs to be fixed in NH Core (=not immediately flushing session when entity with identity Id mapping is used).

RogerKratz avatar Jul 26 '19 20:07 RogerKratz

BTW, why is current behavior causing problems for you?

RogerKratz avatar Jul 26 '19 21:07 RogerKratz

using generator HiLo or something else but identity

That might work, I'll try it out.

My problem is application logic based on assumption of no flushes before commit. For example, I want to create a new entity, get current revision and to perform some recalculations overall entities in the same transaction. So I need to know how to process new entity when recalculating - it might be or not be presented when quering all entities, that depends on whether GetCurrentRevision was called. Such an ambiguity is troubling me. Flushing after each insert/delete would be difficult for the code I am dealing with, I'm not even sure that it won't break something else. And that is why I was hoping to avoid flushes on GetCurrentRevision calls.

akonit avatar Jul 27 '19 08:07 akonit

<< That might work, I'll try it out. >>

Sounds good.

...btw, I assume GetCurrentRevision(false) wont work for you for some reason?

RogerKratz avatar Jul 27 '19 10:07 RogerKratz

Yes, GetCurrentRevision(false) unfortunately is not an option for me

akonit avatar Jul 27 '19 10:07 akonit