<< You should not touch the version property by hand>> Hmm... When passing back DTO:s (that includes version info) from client side to server, it seems impossible not touching the version, assuming server side is stateless and therefore not keeping state of the original Dos between requests?
Or do you mean "don't touch the version by hand on an already created DO"? That makes more sense. I mean, when "transforming" a DO from a DTO, surely the version should be set "by hand"? Or? Thanks /Roger From: [email protected] [mailto:[email protected]] On Behalf Of Fabio Maulo Sent: den 22 maj 2009 15:43 To: [email protected] Subject: [nhusers] Re: Why is NH using version from snapshot? NH use version for optimistic-lock and, where the version is there, to know the state of the entity. You should not touch the version property by hand.. if you want something very special you should write your own IUserVersionType implementation. UPDATE Sample SET Version = @p0, Description = @p1 WHERE id = @p2 AND Version = @p3; @p0 is the new calculate version AND Version = @p3; is the old cached version loaded from DB (this mean optimistic-lock) 2009/5/22 Roger Kratz <[email protected]<mailto:[email protected]>> Hi I just saw a (simplified) code snippet similar to this one in our project var someEntity = fetchFromDb(Dto.Id); [setting props according to the dto, including...] someEntity.SetVersion(dto.Version); Persist(); ...when someEntity is persisted, the generated sql will use the version value from the row "fetchFromDb" and not the value explicitly set the next row. I guess this is because NH is using version value from its internal 1st level cache when flushing (?)? I know that this problem can be solved by skipping the explicit db load and instead relying on Merge(). Another way would be to handle the version check ourselves one way or the other. However - it's pretty easy for an user to write code like above though, assuming that optimistic locking is correctly used. Why is NH behaving this way? Why isn't nh generate sql based on the entity's current version state? Is there any obvious reason that I don't see? Also... If you are not supposed to change the version state on a persisted entity, couldn't nh notice this and throw at persist to prevent code like above? I guess this can be handled using an interceptor or event listeners but why not default? /Roger -- Fabio Maulo --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
