NHibernate 'IdentifierGenerationException' on an Update trigger

Posted by Jan Jongboom on Stack Overflow See other posts from Stack Overflow or by Jan Jongboom
Published on 2010-03-15T11:13:17Z Indexed on 2010/03/15 11:19 UTC
Read the original article Hit count: 274

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about tsql