Вопрос

Currently we are using Sharp Architecture 1.9.6. And we need to audit our domain classes. It seems comfortably to use NHibernate Envers for this task. But I couldn't configure Sharp Architecture to use this library. There were some errors but I solved almost all of these except one.

The error is in following:

For example, I have POCO class named "Document" and table "Documents" in DB. Also I've created table "Documents_AUD" and added attribute [Audited] to class "Document". So, if some object of class Document has changed, Envers must add data to "Documents_AUD" table. To do this Envers create (dynamically?) ovbject of another class - "Document_AUD". And here the error appears: "NHibernate.MappingException No Persister for Document_AUD".

And I don't know where to add mapping for Document_AUD.

Does somebody use Envers with Sharp Arch ? Can somebody share Envers + Sharp Arch configuration?

Thank you very much!

Это было полезно?

Решение

you can create the configuration yourself, configure Envers on it and pass it to NHibernateSession.AddConfiguration() instead of calling the Init method.

Другие советы

The problem is that NHibernate.Envers configuration should take place before building session factory, but after adding hbm mappings to configuration. In SharpArch, when calling NHibernateSession.Init(..), it will build the session factory immediately, adding it to a local cache.

The solution would be to extend NHibernate.Init method, to make use of FluentNHibernate FluentConfiguration API, which has a method

ExposeConfiguration(Action<Configuration> action) 

that is called right after adding fluent mappings.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top