Get last value with nhibernate? -
i have int column each revision create of item. want lastly revision number item , increment 1 , save new revision making.
i bit concerned run issue same item beingness revised @ same time , of sudden got 2 revisions same number.
example
item1 revision 1 item1 revision 2 item2 revision 1 item2 revision 2 item3 revision 1 the above may in database. want add together revision item1. should revision "3".
i want find item 1 had lastly revision of "2" , utilize figure out tit should revision "3".
i worried though multiple people start revision item 1 , submit around same time , revision 2 in memory 3 people revising item 1 , end with
item1 revision 1 item1 revision 2 item1 revision 3 item1 revision 3 (should 4)
edit: 1) in case of updating same row
there nhibernate feature: version or timestamp property , powerful management arround it. seek read here: when utilize nhibernate ? more details. extract
...entity instance has version, can number or timestamp. hibernate increments object’s version when it’s modified, compares versions automatically, , throws exception if conflict detected. consequently, add together version property persistent entity classes enable optimistic locking. ... version number counter value—it doesn’t have useful semantic value.
nhibernate documentation:
5.1.7. version (optional) 5.1.8. timestamp (optional)so, when utilize version gain:
nhibernate increment version value. if trying update row version value old, stale... staleexception thrown. you can append handler solve issue, code.you can utilize more standard features (e.g. interceptors) , audit changes on update different table... current version number.
summary: versioning scheme in nhibernate not solve everything. provided staleexceptions... , have handle them. but, can sure, 1 version @ time stored same version number
edit: 2) tracking new alter new row
please, take suggestion, based on our approach. how implementing changes audit tracking system
the business object e.g. iauditable defined as:
public class article : iauditable { public virtual int id { get; set; } public virtual string text { get; set; } ... // if possible move base of operations more business objects // public virtual ilist<ihistory> history { get; set; } public virtual ilist<articlehistory> history { get; set; } } whenever there update, article itslef updated, , new articlehistory instance created. using hilo generator id, correctly inserted in web-farm.
this approach allows work up-to-date instance of article, improve performance (history in separated table) , supports aop (history tracking turned on/off via injecting auditaopfilter. on detail load history collection.
this suggestion. can understand not suite scenario (and not reply question).
nhibernate
No comments:
Post a Comment