nhibernate-envers
nhibernate-envers copied to clipboard
Unexpected session flush when calling AuditReader.GetCurrentRevision
This is an illustration for the issue: https://github.com/nhibernate/nhibernate-envers/issues/20
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).
BTW, why is current behavior causing problems for you?
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.
<< That might work, I'll try it out. >>
Sounds good.
...btw, I assume GetCurrentRevision(false) wont work for you for some reason?
Yes, GetCurrentRevision(false) unfortunately is not an option for me