Search code examples
nhibernatenhibernate-envers

Envers not Saving Audits-Nhibernate


I have the following envers configuration:

        hibernateCfg.SetEnversProperty(ConfigurationKey.DefaultSchema, "audit");
        hibernateCfg.SetEnversProperty(ConfigurationKey.RevisionFieldName, "Rev");
        hibernateCfg.SetEnversProperty(ConfigurationKey.RevisionTypeFieldName, "RevType");
        hibernateCfg.SetEnversProperty(ConfigurationKey.AuditTableSuffix, "_Audit");

        var cfg = new FluentConfiguration();
        cfg.SetRevisionEntity<RevisionInfo>(x => x.Id, x => x.RevisionTimestamp, new RevisionListener());

        cfg.Audit<User>().Exclude(x=>x.Account).Exclude(x=>x.Agentie).Exclude(x=>x.Location).Exclude(x=>x.Produse).Exclude(x=>x.Roles);
        //cfg.Audit<Account>().ExcludeRelationData(x => x.Users);
        //cfg.Audit<Document>();

        hibernateCfg.IntegrateWithEnvers(new EnhancedAuditEventListener(), cfg);

No Audit Table is created and no data is saved. I have tried creating the table audit.User_Audit myself, but nothing changes. I have nhibernate envers 1.30 and nhibernate 3.3.1.

Do I need another configuration to make this work?


Solution

  • I solved it. The problem was that I had some derived classes from User (Like BrokerUser : User) which I used with discriminators. After I added:

    cfg.Audit<BrokerUser>()
    

    the problem was solved.