0

I'm experimenting with Envers. I've got it working okay, except that when it generated the audit table for my audited entity it made all the varchar columns length 1, rather than the length of the corresponding column in the base table.

Like so:

Object: dbo.COMPANY_ADDRESS_TB

Column          | Type
-----------------------------
ID              | int
COMPANY_ID      | int
ADDRESS_SEQ_NUM | int
TYPE            | varchar(40)
ATTN            | varchar(40)
STREET1         | varchar(60)
STREET2         | varchar(60)
STREET3         | varchar(60)
CITY            | varchar(40)
STATE           | varchar(25)
ZIP             | varchar(18)
COUNTRY         | varchar(25)
TIMESTAMP       | binary(8)
ACTIVE          | int

and then

Object: dbo.COMPANY_ADDRESS_TB_AUD

Column            | Type
------------------------------
ID                | int
REV               | int
REVTYPE           | tinyint
REVEND            | int
ADDRESS_SEQ_NUM   | int
addressSeqNum_MOD | bit
TYPE              | varchar(1)
addressType_MOD   | bit
ATTN              | varchar(1)
attn_MOD          | bit
STREET1           | varchar(1)
street1_MOD       | bit
STREET2           | varchar(1)
street2_MOD       | bit
STREET3           | varchar(1)
street3_MOD       | bit
CITY              | varchar(1)
city_MOD          | bit
STATE             | varchar(1)
state_MOD         | bit
ZIP               | varchar(1)
zip_MOD           | bit
COUNTRY           | varchar(1)
country_MOD       | bit
ACTIVE            | int
active_MOD        | bit

Of course I can change the lengths by hand, but if I start auditing a lot of entities that could get both tedious and error-prone. Here's the code that sets this up:

    var properties = new Dictionary<string, string>();
    properties[NHibernate.Cfg.Environment.Dialect] = "NHibernate.Dialect.MsSql2008Dialect";
    properties[NHibernate.Cfg.Environment.ConnectionDriver] = "NHibernate.Driver.SqlClientDriver";
    properties[NHibernate.Cfg.Environment.Hbm2ddlAuto] = "update";
    properties[NHibernate.Cfg.Environment.FormatSql] = "true";
    properties[NHibernate.Cfg.Environment.ShowSql] = "true";
    properties[NHibernate.Cfg.Environment.ConnectionString] = "Data Source=localhost;Initial Catalog=OU_KASH;Integrated Security=True;Asynchronous Processing=true";
    var cfg = new Configuration();
    cfg.Configure()
        .SetProperties(properties)
        .AddAssembly(typeof(AliasTb).Assembly.FullName)
        ;

    cfg.SetEnversProperty(ConfigurationKey.StoreDataAtDelete, true);
    cfg.SetEnversProperty(ConfigurationKey.AuditStrategy, typeof(NHibernate.Envers.Strategy.ValidityAuditStrategy));
    cfg.SetEnversProperty(ConfigurationKey.TrackEntitiesChangedInRevision, true);
    cfg.SetEnversProperty(ConfigurationKey.GlobalWithModifiedFlag, true);

    cfg.IntegrateWithEnvers(new AttributeConfiguration());

Any idea what I might be doing wrong?

Michael
  • 1,351
  • 1
  • 11
  • 25

2 Answers2

1

Sounds like a potential bug. Please report it here with minimal mapping to reproduce your issue (or even better - create a pull request with a failing test).

Roger
  • 1,944
  • 1
  • 11
  • 17
  • Thanks. I will do as you suggest, but I'm unfamiliar with your follow-up suggestion: How do I "create a pull request with a failing test"? – Michael Oct 28 '15 at 09:56
0

Okay, my bad. In trying to put a minimal example together I created a new class with just an ID and a string property. It turned out that the schema generated for that class as well had a length of 1 for the string column, meaning it had nothing to do with Envers, but rather my entity mapping was wrong (in the example that I originally posted the base table is in a legacy database, not generated by NH). I played around with the <property> attributes and got what I wanted.

Thanks for helping me through this.

Michael
  • 1,351
  • 1
  • 11
  • 25