-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Deleted object not being rolled back
PostPosted: Mon Aug 22, 2005 11:36 am 
Newbie

Joined: Mon Jun 27, 2005 11:49 am
Posts: 7
Location: Norwich, UK
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);
         }
      }


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 6:07 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
What exactly do you mean by "rollback the deleted objects"? The deletions should only actually happen when Commit is called, session.Delete does not issue any SQL, it just adds the object to an internal list of objects to be deleted.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 25, 2005 10:28 am 
Newbie

Joined: Mon Jun 27, 2005 11:49 am
Posts: 7
Location: Norwich, UK
Hi Sergey,

Thanks for the reply.

As per my code I am calling session.Delete() on the objects I would like to delete. Presumably this is marking those session objects as ready to delete. However in the statement outside the loop in the attached code a method I call is throwing an exception (due to a file error). This is still before the Commit() method has been called. However the objects marked for deletion are in fact deleted and calling Rollback() does not rollback the state.

Here's my xml for the SageCustomer entity:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="LogisticsManagement.Core.Components.SageCustomer, Logistics" table="SageCustomers">
    <id name="ID" column="sageCustomerID" type="Int32" unsaved-value="-1">
      <generator class="identity" />
    </id>
    <property name="CustomerID" column="customerID" type="Int32" not-null="true" />
  </class>
</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.