0

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!

Roger
  • 1,944
  • 1
  • 11
  • 17
barser
  • 75
  • 1
  • 10
  • i havent used S#Arch but i think you have to create a nhibernate map file (FluentMapping or hbm.xml) somewhere and give it as mappingassembly to the Init method – Firo Dec 19 '11 at 11:04
  • it's strange but after I did so (hbm.xml) the exception appears - "duplicate mapping entity" – barser Dec 19 '11 at 12:59
  • does the nbm.xml only containes the mapping for "Document_AUD"? and if the mapping file is in the same file as the others do you give the Init the mapping assembly only once? – Firo Dec 19 '11 at 15:02
  • I have separate hbm.xml with mapping for Document_AUD class. This hbm.xml located in MyProject.Data project with other hbm.xml and fluent mappings. On initializing I give path to MyProject.Data.dll as mapping assembly. I can't map Document_AUD fluently because of I don't have source code for Document_AUD class. As far as I understand this class is generated somehow dynamicaly at run-time. Or maybe I'm wrong and I need to create this class by myself? – barser Dec 20 '11 at 07:04
  • there is doc http://docs.jboss.org/envers/docs/index.html maybe it can help you – Firo Dec 20 '11 at 09:34

2 Answers2

2

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.

  • 1
    do you have a full example of how you created the extension please? I'm at a bit of a loss as to where to start! – Rowan Mar 27 '13 at 10:19
0

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

Seif Attar
  • 632
  • 3
  • 9