Hi,
I have a transaction which is doing some work, deleting objects in the db, and then producing a CSV file. The whole lot is within a nHibernate transaction. An exception is being generated in the file creation code which I can see throwing the main exception. However in the catch block of the exception I am calling iTransaction.RollBack(). I presumed that it would rollback the deleted objects but this doesn't seem to be happening. Is there a bug in my code (likely) or nHibernate?
Heres my code to make things a bit clearer:
Code:
public static void GenerateSageCustomerImport(SageCustomerGenerator generator, ISession session)
      {
         IList sageCustomers = null;
         ITransaction tx = null;
         try
         {
            tx = session.BeginTransaction();
            sageCustomers = DataAccessLayer.GetAllSageCustomers(session);
            if (sageCustomers != null)
            {
               /* Load up all the customer refs and put them into a Collection */
               foreach (SageCustomer sageCustomer in sageCustomers)
               {
                  Customer c = (Customer) session.Load(typeof(Customer), sageCustomer.CustomerID);
                  generator.AddCustomer(c);
                  /* Remove the SageCustomer from db session */
                  session.Delete(sageCustomer);
               }
               /* Generate the CSV */
               generator.GenerateCsv(); //exception occuring here
            }
            tx.Commit();
         }
         catch (Exception exc)
         {
            if (tx != null)
               tx.Rollback();
            throw new ApplicationException("ERROR: Could not create CSV. Operation rolled back", exc);
         }
      }