c# - How to swap unique, ordering column entries with NHibernate and Envers? -
i working nhibernate while , nail problem, can neither find answer, nor else how seemed have problem. environment nhibernate 3.3.1.4000 , nhibernate.envers 1.4 history keeping.
i've got database table/entity class of next kind:
public class procedurestep { public virtual int id { get; protected internal set; } public virtual procedure parentobject { get; set; } public virtual int stepno { get; set; } public virtual string name { get; set; } }
with mapping:
public class procedurestepmap : classmap<procedurestep> { public procedurestepmap() { table("procedurestep"); id(x => x.id); references(x => x.parentobject).not.nullable().uniquekey("uk_po_sn"); map(x => x.stepno).not.nullable().uniquekey("uk_po_sn"); map(x => x.name).not.nullable(); } }
we have parent object list of procedure steps. user can add, delete or modify different steps. 1 "modification" alter of ordering of procedure steps using button move selected item or downwards in list of steps.
let's create concrete example:
the scenario list of 4 procedure steps 1-4:
(1) aaaa (2) bbbb <-- (3) cccc (4) dddd
the users selectes sec item "bbbb" , presses "up" button, get:
(1) bbbb <-- (2) aaaa (3) cccc (4) dddd
in code thought of doing like
begin transaction 1) set "aaaa" stepno = 0 2) set "bbbb" stepno = 1 3) set "aaaa" stepno = 2 end transaction
but nhibernates get's play. nhibernate not know step 1 when committing transaction, , hence trying work 2 update commands database (steps 2 , 3), not working, due unique character of stepno column. adding session.flush() after step 1 not changing behaviour (quite understandable me, within transaction).
the next thought using session.createquery("update...").executeupdate()
changes on database, working fine, working around envers , leaving me without history record alter (quite understandable 1 time again, sql passed on).
but right way change, having in 1 transaction , having history of envers? be, not making "stepno" column unique way working? loosing unique character of column not wanted, of import have propper ordering , having database ensuring this, great help.
thanks upfront ideas!
[solution]:
jbl , cremor seem have answers. other points of trouble, decided skip envers completly , utilize more specialized way of doing history management, less general, more adapted our needs. no envers, problem solved simple 3-step update using sql commands.
if database supports deferrable constraints utilize them.
c# .net nhibernate swap nhibernate-envers
No comments:
Post a Comment