1

I have tried to make ENVERS (Audit and Logging Tool for NHibernate) work with the ValidityAuditStrategy strategy, but I have'nt been successfull.

My NHibernate (fluent using envers extension method) looks like this:

        var fluentConfiguration = Fluently.Configure()
                                          .Database(msSqlConfiguration)
                                          .Mappings(m =>
                                           m.FluentMappings.AddFromAssemblyOf<MetaObject>())
                                          .Mappings(m =>
                                                    m.FluentMappings.Conventions.AddFromAssemblyOf<MetaObject>())
                                          .ExposeConfiguration(cfg =>
                                          {
                                              cfg.EventListeners.PreInsertEventListeners =
                                                  new IPreInsertEventListener[] { new SimpleAuditEventListener() };
                                              cfg.EventListeners.PreUpdateEventListeners =
                                                  new IPreUpdateEventListener[] { new SimpleAuditEventListener() };

                                              // ENVERS 
                                              cfg.IntegrateWithEnvers(GetEnversConfiguration()); // this is ok
                                              // ENVERS Strategy
                                              //cfg.SetProperty("nhibernate.envers.audit_strategy ", typeof(ValidityAuditStrategy).AssemblyQualifiedName); // does not work :-(
                                              cfg.SetProperty("nhibernate.envers.audit_strategy ", "NHibernate.Envers.Strategy.ValidityAuditStrategy"); // does not work :-(
                                              cfg.SetEnversProperty(ConfigurationKey.AuditStrategy, typeof(ValidityAuditStrategy));  // does not work :-(

                                          }
            ).ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(false, true));

I have different ways to configure the audit strategy, but the default strategy is always used. When using validity strategy, the created audit tables should have an additional columns "REVEND". However, this is not the case and I am a bit at loss at what I should try next.

Is my configuration wrong? Or is it not possible to have the sql tables created by NHibernate (I do this with the last line of the configuration).

Any help is appreciated. Thanks

4

1 回答 1

1

您需要在调用 IntegrateWithEnvers 之前设置 (envers) 属性。我不太了解流利的 nhibernate,但是查看代码,它看起来 AuditStrategy 是在调用 IntegrateWithEnvers 之后设置的。

于 2013-10-07T19:59:47.497 回答