2015-10-26 44 views
0

我有以下配置來設置NH和Envers起來:NHibernate Envers ValidityAuditStrategy - 我做錯了什麼?

var properties = new Dictionary<string, string>(); 
properties[NHibernate.Cfg.Environment.Dialect] = "NHibernate.Dialect.MsSql2008Dialect"; 
properties[NHibernate.Cfg.Environment.ConnectionDriver] = "NHibernate.Driver.SqlClientDriver"; 
properties[NHibernate.Cfg.Environment.Hbm2ddlAuto] = "update"; 
properties[NHibernate.Cfg.Environment.FormatSql] = "true"; 
properties[NHibernate.Cfg.Environment.ShowSql] = "true"; 
properties[NHibernate.Cfg.Environment.ConnectionString] = "Data Source=localhost;Initial Catalog=OU_KASH;Integrated Security=True;Asynchronous Processing=true"; 
var cfg = new Configuration(); 
cfg.Configure() 
    .SetProperties(properties) 
    .AddAssembly(typeof(AliasTb).Assembly.FullName) 
    ; 

cfg.SetEnversProperty(ConfigurationKey.StoreDataAtDelete, true); 
cfg.SetEnversProperty(ConfigurationKey.AuditStrategy, typeof(NHibernate.Envers.Strategy.ValidityAuditStrategy)); 
cfg.SetEnversProperty(ConfigurationKey.TrackEntitiesChangedInRevision, true); 
cfg.SetEnversProperty(ConfigurationKey.GlobalWithModifiedFlag, true); 

cfg.IntegrateWithEnvers(new AttributeConfiguration()); 

var factory = cfg.BuildSessionFactory(); 

如果我離開關

cfg.SetEnversProperty(ConfigurationKey.AuditStrategy, typeof(NHibernate.Envers.Strategy.ValidityAuditStrategy)); 

它工作正常,但該選項我得到下面的異常時,我承諾我交易(更新CompanyAddressTb對象):

ERROR NHibernate.AssertionFailure - An AssertionFailure occurred - this may indicate a bug in NHibernate or in your custom types. 
System.InvalidOperationException: Cannot find previous revision for entity NhDoodling.Entities.Domain.CompanyAddressTb_AUD and id 12962904 
    at NHibernate.Envers.Strategy.ValidityAuditStrategy.updateLastRevision(ISession session, AuditConfiguration auditCfg, IList l, Object id, String auditedEntityName, Object revision, Boolean throwIfNotOneEntry) 
    at NHibernate.Envers.Strategy.ValidityAuditStrategy.Perform(ISession session, String entityName, Object id, Object data, Object revision) 
    at NHibernate.Envers.Synchronization.Work.AbstractAuditWorkUnit.Perform(ISession session, Object revisionData) 
    at NHibernate.Envers.Synchronization.AuditProcess.executeInSession(ISession executeSession) 
    at NHibernate.Envers.Synchronization.AuditProcess.DoBeforeTransactionCompletion() 
    at NHibernate.Envers.Synchronization.AuditProcessManager.<>c__DisplayClass4.<Get>b__0() 
    at NHibernate.Engine.ActionQueue.BeforeTransactionCompletionProcessQueue.BeforeTransactionCompletion() 

任何幫助將不勝感激。

回答

0

如果您開始在非空數據庫上使用Envers,則需要在審計表中手動插入當前數據。

瞭解更多here