UnitOfWork2 and Transaction

Posts   
 
    
Posts: 48
Joined: 24-Nov-2010
# Posted on: 12-Jan-2011 09:57:39   

LLBLGEN 3.0 8/12/2010 Oracle 9/10g MSORACLE .NET Framework 2.0

I am trying to update 2 entities with UOW and transaction. 1st entity updates and 2nd entity fails to update. In this case it should actually rollback. But transaction commits !

Code snippet

var adapterdebitnote = new DataAccessAdapter(); adapterdebitnote.StartTransaction(IsolationLevel.ReadCommitted, "DebitNote"); var BulkInsertDebitnote = new UnitOfWork2(); try { var debitnote = new CreditdebitnoteEntity(Convert.ToInt32(GlobalVariable.searchDebitNoteid)); adapterdebitnote.FetchEntity(debitnote); debitnote.IsNew = false; ......................... ........................ BulkInsertDebitnote.AddForSave(debitnote);

var monthlybill = new MonthlybillEntity(Convert.ToInt32(MonthBillID)); adapterdebitnote.FetchEntity(monthlybill); monthlybill.IsNew = false; ..................... ........................... BulkInsertDebitnote.AddForSave(monthlybill); BulkInsertDebitnote.Commit(adapterdebitnote, true); catch (Exception ex) { GlobalErrorHandler.LogMessage(ex.Message + ex.StackTrace); return; }

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Jan-2011 10:38:51   

2nd entity fails to update

What do you mean by failed to update? Do you have any idea why it failed to update? Is there any exception thrown?

Posts: 48
Joined: 24-Nov-2010
# Posted on: 12-Jan-2011 10:43:25   

Walaa wrote:

2nd entity fails to update

What do you mean by failed to update? Do you have any idea why it failed to update? Is there any exception thrown?

I meant monthlybill entity failed to update(update entity). but creditdebit entity updated successully.

Yes I know why it failed. I tried to fetch monthlybill with PK 0 which does not exist.

But My question was why did it commit creditdebitnote when update action on monthlybill failed ?

Exception Error Messagesmile uring a save action an entity's update action failed. The entity which failed is enclosed. at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.PersistQueue(List`1 queueToPersist, Boolean insertActions, Int32& totalAmountSaved) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.0\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 1446 at SD.LLBLGen.Pro.ORMSupportClasses.UnitOfWork2.Commit(IDataAccessAdapter adapterToUse, Boolean autoCommit) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.0\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\UnitOfWork\UnitOfWork2.cs:line 879 at ClubCentric.Transaction.TransactionDebitNote.ReverseData() in D:\ProjectLive\ClubCentric\Transaction\TransactionDebitNote.cs:line 649

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Jan-2011 16:12:23   

What happens if you modify the code to use the following:

BulkInsertDebitnote.Commit(adapterdebitnote);
adapterdebitnote.Commit();
catch (Exception ex)
            {
                adapterdebitnote.Rollback();
                GlobalErrorHandler.LogMessage(ex.Message + ex.StackTrace);
                return;
            }
Posts: 48
Joined: 24-Nov-2010
# Posted on: 12-Jan-2011 17:09:46   

Walaa wrote:

What happens if you modify the code to use the following:

BulkInsertDebitnote.Commit(adapterdebitnote);
adapterdebitnote.Commit();
catch (Exception ex)
            {
                adapterdebitnote.Rollback();
                GlobalErrorHandler.LogMessage(ex.Message + ex.StackTrace);
                return;
            }

Still does not roll back.

Error Error Messagesmile uring a save action an entity's update action failed. The entity which failed is enclosed. at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.PersistQueue(List`1 queueToPersist, Boolean insertActions, Int32& totalAmountSaved) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.0\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\AdapterSpecific\DataAccessAdapterBase.cs:line 1446 at SD.LLBLGen.Pro.ORMSupportClasses.UnitOfWork2.Commit(IDataAccessAdapter adapterToUse, Boolean autoCommit) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.0\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\UnitOfWork\UnitOfWork2.cs:line 879 at SD.LLBLGen.Pro.ORMSupportClasses.UnitOfWork2.Commit(IDataAccessAdapter adapterToUse) in c:\Myprojects\VS.NET Projects\LLBLGen Pro v3.0\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\UnitOfWork\UnitOfWork2.cs:line 706 at ClubCentric.Transaction.TransactionDebitNote.ReverseData() in D:\ProjectLive\ClubCentric\Transaction\TransactionDebitNote.cs:line 647

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Jan-2011 17:45:32   

I'm sorry but I couldn't reproduce it. I used the following code against Northwind.

            var adapterdebitnote = new DataAccessAdapter();
            adapterdebitnote.StartTransaction(IsolationLevel.ReadCommitted, "TestRollback");
            var uow = new UnitOfWork2();
            try
            {
                var product = new ProductEntity(77);
                adapterdebitnote.FetchEntity(product);
                product.IsNew = false;
                product.QuantityPerUnit = "50";

                uow.AddForSave(product);

                var order = new OrderEntity(10248);
                adapterdebitnote.FetchEntity(order);
                order.IsNew = false;
                order.CustomerId = "FALSE";

                uow.AddForSave(order);
                uow.Commit(adapterdebitnote, true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
                return;
            }

The second save fails because there is no CustomerID with the value "FALSE". So this produced a FK violation exception. And then the first save operation was not commited.

Posts: 48
Joined: 24-Nov-2010
# Posted on: 12-Jan-2011 19:03:36   

Walaa wrote:

I'm sorry but I couldn't reproduce it. I used the following code against Northwind.

            var adapterdebitnote = new DataAccessAdapter();
            adapterdebitnote.StartTransaction(IsolationLevel.ReadCommitted, "TestRollback");
            var uow = new UnitOfWork2();
            try
            {
                var product = new ProductEntity(77);
                adapterdebitnote.FetchEntity(product);
                product.IsNew = false;
                product.QuantityPerUnit = "50";

                uow.AddForSave(product);

                var order = new OrderEntity(10248);
                adapterdebitnote.FetchEntity(order);
                order.IsNew = false;
                order.CustomerId = "FALSE";

                uow.AddForSave(order);
                uow.Commit(adapterdebitnote, true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
                return;
            }

The second save fails because there is no CustomerID with the value "FALSE". So this produced a FK violation exception. And then the first save operation was not commited.

Hi walaa

What if PK itself does not exist? I mean what if these lines returns 0 rows var order = new OrderEntity(1024sunglasses ; adapterdebitnote.FetchEntity(order);

This is what is happening in my case.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Jan-2011 06:53:51   

yogesh.shtty wrote:

Walaa wrote:

I'm sorry but I couldn't reproduce it. I used the following code against Northwind.

            var adapterdebitnote = new DataAccessAdapter();
            adapterdebitnote.StartTransaction(IsolationLevel.ReadCommitted, "TestRollback");
            var uow = new UnitOfWork2();
            try
            {
                var product = new ProductEntity(77);
                adapterdebitnote.FetchEntity(product);
                product.IsNew = false;
                product.QuantityPerUnit = "50";

                uow.AddForSave(product);

                var order = new OrderEntity(10248);
                adapterdebitnote.FetchEntity(order);
                order.IsNew = false;
                order.CustomerId = "FALSE";

                uow.AddForSave(order);
                uow.Commit(adapterdebitnote, true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
                return;
            }

The second save fails because there is no CustomerID with the value "FALSE". So this produced a FK violation exception. And then the first save operation was not commited.

Hi walaa

What if PK itself does not exist? I mean what if these lines returns 0 rows var order = new OrderEntity(1024sunglasses ; adapterdebitnote.FetchEntity(order);

This is what is happening in my case.

No difference for me. The rollback happened, everything is ok.

David Elizondo | LLBLGen Support Team
Posts: 48
Joined: 24-Nov-2010
# Posted on: 13-Jan-2011 08:14:45   

daelmo wrote:

yogesh.shtty wrote:

Walaa wrote:

I'm sorry but I couldn't reproduce it. I used the following code against Northwind.

            var adapterdebitnote = new DataAccessAdapter();
            adapterdebitnote.StartTransaction(IsolationLevel.ReadCommitted, "TestRollback");
            var uow = new UnitOfWork2();
            try
            {
                var product = new ProductEntity(77);
                adapterdebitnote.FetchEntity(product);
                product.IsNew = false;
                product.QuantityPerUnit = "50";

                uow.AddForSave(product);

                var order = new OrderEntity(10248);
                adapterdebitnote.FetchEntity(order);
                order.IsNew = false;
                order.CustomerId = "FALSE";

                uow.AddForSave(order);
                uow.Commit(adapterdebitnote, true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
                return;
            }

The second save fails because there is no CustomerID with the value "FALSE". So this produced a FK violation exception. And then the first save operation was not commited.

Hi walaa

What if PK itself does not exist? I mean what if these lines returns 0 rows var order = new OrderEntity(1024sunglasses ; adapterdebitnote.FetchEntity(order);

This is what is happening in my case.

No difference for me. The rollback happened, everything is ok.

Well, noticed something strange. First time it rolls back correctly. Second time it does not. When ever I exit the application login again and run this code it works. This is really strange. Every action I am clearing all variables but still the problem persists.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Jan-2011 08:37:10   

I can't produce that either. If I run it multiple times, it succeeds every time.

Posts: 48
Joined: 24-Nov-2010
# Posted on: 13-Jan-2011 08:50:04   

Walaa wrote:

I can't produce that either. If I run it multiple times, it succeeds every time.

Well, do you see any issues in this complete code what i have written. I mean the way i have used UOW and adapters

private void ReverseData() { var adapterdebitnote = new DataAccessAdapter(); adapterdebitnote.StartTransaction(IsolationLevel.ReadCommitted, "DebitNote"); var BulkInsertDebitnote = new UnitOfWork2(); decimal Total = 0; string TransactionMonth = string.Format("{0:MMMM-yyyy}", datenotedate.Value.Date).ToUpper(); try { var debitnote = new CreditdebitnoteEntity(Convert.ToInt32(GlobalVariable.searchDebitNoteid)); adapterdebitnote.FetchEntity(debitnote); int MonthBillID = MonthlyBill.returnmonthlybillid(TransactionMonth, ValidateUI.GetComboboxNullable( debitnote.EmployeeId), ValidateUI.GetComboboxNullable( debitnote.AffiliateclubId), ValidateUI.GetComboboxNullable( debitnote.MemberId), ValidateUI.GetComboboxNullable( debitnote.CorporateId), ValidateUI.GetComboboxNullable( debitnote.AffiliatememberId));

            #region CreditDebitNote Entity

            debitnote.IsNew = false;
            debitnote.Flag = StandardFlag.recorddeleteflag;
            debitnote.ReasonId = Convert.ToInt32(cmbreasonid.SelectedValue);
            debitnote.Modifieddate = ServerDateTime.getcurrentserverdatewithtime();
            debitnote.ModifieduserId = StandardMessage.loginuserid;
            BulkInsertDebitnote.AddForSave(debitnote);

            #endregion CreditDebitNote Entity

            for (int i = 0; i < dgriddebitnote.Rows.Count - 1; i++)
            {
                Total = Total +
                        Convert.ToDecimal(dgriddebitnote.Rows[i].Cells["DEBITAMOUNT"].Value);
            }

            #region Monthlybill Entity

            var monthlybill = new MonthlybillEntity(Convert.ToInt32(MonthBillID));
            monthlybill.IsNew = false;
            monthlybill.Fields[(int) MonthlybillFieldIndex.Debitamount].
                ExpressionToApply =
                (MonthlybillFields.Debitamount - Convert.ToDecimal(Total));
            monthlybill.Fields[(int) MonthlybillFieldIndex.Balanceamount].
                ExpressionToApply =
                (MonthlybillFields.Balanceamount - Convert.ToDecimal(Total));
            monthlybill.Modifieddate = ServerDateTime.getcurrentserverdatewithtime();
            monthlybill.ModifieduserId = StandardMessage.loginuserid;
            BulkInsertDebitnote.AddForSave(monthlybill);

            #endregion Monthlybill Entity

            #region Monthlybilldetail Entity

            for (int i = 0; i < dgriddebitnote.Rows.Count - 1; i++)
            {
                int MonthlybillDetailid =
                    Ledger.MonthlyBillDetailId(
                        Convert.ToInt32(dgriddebitnote.Rows[i].Cells["LEDGER_ID"].Value),
                        GlobalVariable.optionNo, MonthBillID);
                if (MonthlybillDetailid <= 0) continue;
                var monthlybilldetail =
                    new MonthlybilldetailEntity(MonthlybillDetailid);
                monthlybilldetail.IsNew = false;
                monthlybilldetail.Fields[(int) MonthlybilldetailFieldIndex.Debitamount]
                    .ExpressionToApply =
                    (MonthlybilldetailFields.Debitamount -
                     Convert.ToDecimal(dgriddebitnote.Rows[i].Cells["DEBITAMOUNT"].Value));
                monthlybilldetail.Modifieddate =
                    ServerDateTime.getcurrentserverdatewithtime();
                monthlybilldetail.ModifieduserId = StandardMessage.loginuserid;
                BulkInsertDebitnote.AddForSave(monthlybilldetail);

                #endregion Monthlybilldetail Entity
            }
            BulkInsertDebitnote.Commit(adapterdebitnote,true);

            {
                MessageBox.Show(StandardMessage.datasavesuccess);
                DoRefresh();
            }
        }
        catch (Exception ex)
        {

            GlobalErrorHandler.LogMessage(ex.Message + ex.StackTrace);
            return;
        }
        finally
        {
            adapterdebitnote.CloseConnection();
            adapterdebitnote.Dispose();
        }
    }

I hope it is not issue with MSORALCE of LLBLGEN

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Jan-2011 09:08:48   

I see nothing wrong in your code.

Could you please test with ODP.NET?

Posts: 48
Joined: 24-Nov-2010
# Posted on: 13-Jan-2011 09:29:22   

Walaa wrote:

I see nothing wrong in your code.

Could you please test with ODP.NET?

ODP.NET works fine. Issue remains same with MSORACLE. Something some where is wrong becoz in MSORACLE it works only when I Exit the application and reopen every time.

And this is not the first time. All updates even without UOW in MSORACLE, i see bugs like not being updated on second and subsequent exeuctions

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Jan-2011 10:16:32   

One final test, would this work using vanilla ADO.NET (using the Microsoft provider)?

Posts: 48
Joined: 24-Nov-2010
# Posted on: 13-Jan-2011 10:23:25   

Walaa wrote:

One final test, would this work using vanilla ADO.NET (using the Microsoft provider)?

Well how do I test with vanilla ADO.NET

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Jan-2011 10:34:29   

Using normal ADO.NET System.Data.OracleClient classes. Test the Update issue. If it can do updates on the second round.

Posts: 48
Joined: 24-Nov-2010
# Posted on: 13-Jan-2011 10:47:06   

Walaa wrote:

Using normal ADO.NET System.Data.OracleClient classes. Test the Update issue. If it can do updates on the second round.

It works. Because our present project is based on same concept but without LLBLGEN.

Since we found LLBLGEN more efficient and easy to manage, we are just rebuilding the project on LLBLGEN.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 15-Jan-2011 12:08:11   

This is a known bug in MS Oracle.

See: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=14135

Frans Bouma | Lead developer LLBLGen Pro