This is not the behaviour of the NHibernate, but DB Engine.
Please, check this question: SQL Identity (autonumber) is Incremented Even with a Transaction Rollback
For testing purposes you can use different generators, e.g. Increment
, which are managed by NHiberante and after rollback and restart ... the value is reset. Check 5.1.4.1. generator, an extract:
increment
generates identifiers of any integral type that are unique only when no other process is inserting data into the same table. Do not use in a cluster.