With the mapping you have, the ”SettingValue” is supposed to be part in the audited table’s primary key. Or rather – part of the generated audited composite-id mapping for ”HardwareSettings”.
<< Has someone an idea where to hook in to change the way Envers creates the schema for the audit tables?> Envers doesn't create any schema for you. I guess you use NH Core's schemaexport to generate the schema for you? That tool will generate schema for your NH configuration object (which also contains mapping for envers audited entities). I understand this will lead to problem if this pk contains a “StringClobUserType” mapping. If you manually drop/change your pk after it has been generated by “X” (=schemaexport), will things work as expected for you then? From: nhusers@googlegroups.com [mailto:nhusers@googlegroups.com] On Behalf Of Matthias Kientz Sent: den 8 oktober 2015 15:56 To: nhusers <nhusers@googlegroups.com> Subject: [nhusers] Envers: erroneous primary key for mapped collection I use NHibernate with Fluent and Envers. I have an auditable class Hardware, which contains the property Settings, which is mapped to a collection entity. Error: The created audit table adds also the value column (SettingValue) to the primary key, which fails in this case (SqlCeException: Long value data type cannot be indexed.) Expected: The value column SettingValue should not be part of the primary key. /* definition of Setting (in class Hardware) */ public virtual IDictionary<string, string> Settings { get { return _settings; } set { _settings = value; } } /* automapping override with fluent */ mapping.HasMany(x => x.Settings) .Not.LazyLoad() .AsMap<string>("SettingName") .KeyColumns.Add("HardwareSettings_id") .Table("HardwareSettings") .Element("SettingValue", x => x.Type<StringClobUserType>()); /* trace of the resulting Hardware mapping (containing map HardwareSettings) */ <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> <class xmlns="urn:nhibernate-mapping-2.2" name="MyApp.Data.Model.Hardware.Hardware, MyApp.Data.Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=866d4a0fa0599fe0" table="`Hardware`"> <cache usage="read-write" /> <id name="Id" type="System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <column name="Id" /> <generator class="guid.comb" /> </id> <map cascade="save-update" lazy="false" name="Settings" table="HardwareSettings"> <cache usage="read-write" /> <key> <column name="HardwareSettings_id" /> </key> <index type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <column name="SettingName" /> </index> <element type="MyApp.DataAccess.NHibernate.UserTypes.StringClobUserType, MyApp.DataAccess.NHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=866d4a0fa0599fe0"> <column name="SettingValue" /> </element> </map> <!-- several other properties and subclasses --> </class> </hibernate-mapping> /* trace of the resulting HardwareSettings autition table mapping */ <hibernate-mapping assembly="NHibernate.Envers" auto-import="false" xmlns="urn:nhibernate-mapping-2.2"> <class entity-name="HardwareSettings_AUD" table="HardwareSettings_AUD"> <composite-id name="originalId"> <key-many-to-one class="NHibernate.Envers.DefaultRevisionEntity, NHibernate.Envers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e2c5b946037fb7f8" name="REV"> <column name="REV" /> </key-many-to-one> <key-property name="Hardware_Id" type="Guid"> <column name="HardwareSettings_id" /> </key-property> <key-property name="element" type="MyApp.DataAccess.NHibernate.UserTypes.StringClobUserType, MyApp.DataAccess.NHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=866d4a0fa0599fe0"> <column name="SettingValue" /> <type name="MyApp.DataAccess.NHibernate.UserTypes.StringClobUserType, MyApp.DataAccess.NHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=866d4a0fa0599fe0" /> </key-property> <key-property name="mapkey" type="String"> <column name="SettingName" /> </key-property> </composite-id> <property insert="true" update="false" name="REVTYPE" type="NHibernate.Envers.Entities.RevisionTypeType, NHibernate.Envers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e2c5b946037fb7f8" not-null="true" /> </class> </hibernate-mapping> /* created HardwareSettings table */ create table HardwareSettings ( HardwareSettings_id UNIQUEIDENTIFIER not null, SettingValue NTEXT null, SettingName NVARCHAR(255) not null, primary key (HardwareSettings_id, SettingName) ) /* created HardwareSettings audition table (with erroneous primary key) */ create table HardwareSettings_AUD ( REV INT not null, HardwareSettings_id UNIQUEIDENTIFIER not null, SettingValue NTEXT not null, SettingName NVARCHAR(255) not null, REVTYPE TINYINT not null, primary key (REV, HardwareSettings_id, SettingValue, SettingName) ) If this cannot be solved by myself or via configuration: Has someone an idea where to hook in to change the way Envers creates the schema for the audit tables? -- You received this message because you are subscribed to the Google Groups "nhusers" group. To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+unsubscr...@googlegroups.com<mailto:nhusers+unsubscr...@googlegroups.com>. To post to this group, send email to nhusers@googlegroups.com<mailto:nhusers@googlegroups.com>. Visit this group at http://groups.google.com/group/nhusers. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "nhusers" group. To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+unsubscr...@googlegroups.com. To post to this group, send email to nhusers@googlegroups.com. Visit this group at http://groups.google.com/group/nhusers. For more options, visit https://groups.google.com/d/optout.