nhibernate-envers

Envers with Nhibernate


I am using Envers for auditing some of my DB Tables. Auditing is woking fine, I can see the data in the DB in the corresponding tables with my custom prefix etc. I can't query any data becouse I am getting always the following QueryException:

could not resolve property: originalId of: NaturalPerson [select e__, r__ from NaturalPerson e__, ExtendedRevisionEntity r__ where e__.originalId.RevisionID.id = r__.id order by e__.originalId.RevisionID.id asc]

This is the query code:

AuditReaderFactory.Get(session).CreateQuery().ForHistoryOf<NaturalPerson, ExtendedRevisionEntity>().Results();

Mappings for NaturalPerson

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping assembly="Domain" namespace="Domain" xmlns="urn:nhibernate-mapping-2.2">
  <joined-subclass name="NaturalPerson"  schema="MySchema" table="NaturalPersons">
    <key column="PersonID" />
    <property name="Name" type="AnsiString"/>
  </joined-subclass>
</hibernate-mapping>

Envers config using fluent:

configuration.SetEnversProperty(ConfigurationKey.AuditTableSuffix, " ");
configuration.SetEnversProperty(ConfigurationKey.DefaultSchema, "aud"); 
configuration.SetEnversProperty(ConfigurationKey.StoreDataAtDelete, true);
configuration.SetEnversProperty(ConfigurationKey.RevisionFieldName, "RevisionID");
configuration.SetEnversProperty(ConfigurationKey.RevisionTypeFieldName, "RevisionTypeID");
enversConf.Audit<NaturalPerson>();

Solution

  • As stated in the comments above, the problem is the "only spaces" in the AuditTableSuffix.

    The audited entity name in code is audittableprefix + "original entity name" + audittablesuffix

    When querying, the "empty space" means nothing ("select a from b a" becomes "select a from b a") and wrong data will be read.

    Please add a JIRA issue about it here https://nhibernate.jira.com/browse/NHE preferably with a small, isolated failing test.