NHibernate 'null identifier' error

Today I received a strange null identifier error when saving an object to db with nhibernate. Immediatly I realize that this error is caused by a Trigger INSTEAD OF INSERT, that apperars to broke the SCOPE_IDENTITY() function. Since NHibernate uses SCOPE_IDENTITY() to retrieve the id of the generated object, when you use INSTEAD OF INSERT Trigger the SCOPE_IDENTITY() returns null, and nhibernate could not know the value of the inserted record.

I first tried to specify with <sql.insert> the query to use, to make use of @@identity, but it does not work. After some time I discovered a issue that was fixed only in the trunk. My only solution was removing the trigger (fortunately I can do it) because nhibernate does not permits me to use <sql-insert> with entities that use identity to generate ids.

Another good reason not to use identity with nhibernate, but my project is a legacy one where a lot of operations are massive ones performed by stored procedure.

alk.