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]>

>  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 1stlevel 
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to