0

All the examples I have seen for NHibernate.Envers use an integer as the object id's. I would like to use Guid's instead. Is this possible?

[Audited]
public class Person
{
    public virtual Guid Id { get; set; }
    public virtual String FirstName { get; set; }
    public virtual String LastName { get; set; }
    public virtual int Age { get; set; }
    public virtual Address.Address Address { get; set; }
}

I am asking because I am seeing an exception when trying to save the REV data:

[Sql String]: INSERT INTO REVINFO (REVTSTMP) VALUES (?); select SCOPE_IDENTITY()

{"Cannot insert the value NULL into column 'REV', table 'Auditing.dbo.REVINFO'; 
  column does not allow nulls. INSERT fails.\r\nThe statement has been terminated."}

My revision data object has an Id of 0.

gwin003
  • 7,432
  • 5
  • 38
  • 59

1 Answers1

1

Yes, your entites can have pretty much any id type (that NHibernate Core supports). The revision entity must have a number though.

About your exception... Most probably there's something wrong with your revision entity and/or its mapping. Read the docs here, http://envers.bitbucket.org/#revisionlog.

Roger
  • 1,944
  • 1
  • 11
  • 17
  • Thanks Roger, I was able to get it working yesterday. So there is no way to make the `REV` on `REVINFO` a `Guid`? I have concerns with using an `int` or even a `bigint` because eventually those will overflow. – gwin003 Jan 29 '15 at 12:26
  • Envers uses this field for a lot of internal queries like "revision id larger than..", "revision id between..", eg when reading relationships. – Roger Jan 29 '15 at 12:52
  • ...so no, I don't think it is possible to "solve". In short terms - each revision needs to have som unique value that is "comparable". – Roger Jan 29 '15 at 12:53