I am using a Firebird database and NHibernate for object mapping. I have a table called Product
with the typical fields like ID
and ProductName
, and I'm using Firebird's native ID generator to auto-generate the ID for me. When I was doing some testing, I had some code similar to the below:
session.Save(product);
try
{
transaction.Commit();
}
catch
{
//couldn't save
transaction.Rollback();
}
finally
{
session.Close();
}
The idea was to try and save the product, and if it didn't work, rollback the changes. When I tested this, the record was indeed not saved, but the native ID generator had been changed. For example, the generator was supposed to start at value 1. When I tried to add a 'bad' record using the code above, the record wouldn't save but the generator would jump to value 2. So, is there a way for me to also rollback any changes to the ID generator?
Thanks in advance.