NHibernate 'IdentifierGenerationException' on an Update trigger
- by Jan Jongboom
In my database I have an id column defined as [autonumber] [int] IDENTITY(1,1) NOT NULL which is mapped in my .hbm.xml like:
<id name="Id" column="autonumber" type="int">
<generator class="identity" />
</id>
When calling session.Save() updates are successful committed to the database.
When adding a versioning trigger I however get the error this id generator generates Int64, Int32, Int16 of type IdentifierGenerationException.
The trigger is defined as:
ALTER TRIGGER [dbo].[CatchUpdates_NVM_FDK_Kenmerken]
ON [dbo].[NVM_FDK_Kenmerken]
INSTEAD OF UPDATE
AS
BEGIN
SET NOCOUNT ON
UPDATE NVM_FDK_Kenmerken SET idIsActive = 0 WHERE internalId IN (SELECT internalId FROM INSERTED)
INSERT INTO dbo.NVM_FDK_Kenmerken
( vestigingNummer , internalId , someOtherColumns, dateInserted, idIsActive )
SELECT vestigingNummer, internalId, someOtherColumns, GETDATE(), 1
FROM INSERTED
END
What am I doing wrong here? When doing manual updates everything works just fine and as expected.