NHibernate: Modifying different fields of an entity from two sessions -
i have entity multiple fields. there 2 types of actions may performed on it: long one, initiated user, , short one, periodically run system. both of these update entity, touch different fields.
there can't 2 concurrent long operations or 2 concurrent short operations. system may schedule short operation while long operation in progress, , 2 should execute concurrently. since touch different fields, believe should possible.
i think nhibernate's change tracking should trick here - i.e., if 1 session loads entity , updates fields, , session loads same entity , updates different fields, 2 not collide. however, feel shouldn't relying on because sounds "optimization" or "implementation detail". tend think of change tracking optimization reduce database traffic, don't want functionality of system depend on it. also, if ever decide implement optimistic concurrency entity, risk getting staleobjectexception, though can guarantee there no actual collision.
what best way achieve this? should split entity two? can't affect database consistency (e.g. if 1 "half" of entity in db)? can use nhibernate explicitly set single field of entity? wrong in not wanting rely on change tracking achieve functionality?
if matters, i'm using fluent nhibernate.
you map entity using dynamic update.
dynamic-update(optional, defaults false): specifies update sql should generated @ runtime , contain columns values have changed.
if enable dynamic-update, have choice of optimistic locking strategies:
versioncheck version/timestamp columnsallcheck columnsdirtycheck changed columnsnonenot use optimistic locking
more information here.
Comments
Post a Comment