a different object with the same identifier value was...

For general questions and discussions specific to the AbleCommerce GOLD ASP.Net shopping cart software.
Post Reply
User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

a different object with the same identifier value was...

Post by AbleMods » Wed May 01, 2013 3:15 pm

I'm trying to add an order-note to an existing order. I can't even get it to work a simple page. I still get the error. It seems like such a basic thing to do. Do I need to restart the whole app or something? What am I doing wrong?

Here's the only code:

Code: Select all

    protected void Page_Load(object sender, EventArgs e)
    {
        OrderNote _Note = new OrderNote();
        _Note.OrderId = 1;
        _Note.NoteType = NoteType.SystemPrivate;
        _Note.Comment = "test order note by Joe";
        _Note.Save();
    }
And here's the error I get every time:
a different object with the same identifier value was already associated with the session: 17, of entity: CommerceBuilder.Orders.OrderNote

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: NHibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 17, of entity: CommerceBuilder.Orders.OrderNote

Source Error:


Line 15: _Note.NoteType = NoteType.SystemPrivate;
Line 16: _Note.Comment = "test order note by Joe";
Line 17: _Note.Save();
Line 18: }
Line 19: }

Source File: c:\AbleMods-Modules\ReturnsManager-Gold\Site\test-ordernote.aspx.cs Line: 17

Stack Trace:


[NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 17, of entity: CommerceBuilder.Orders.OrderNote]
CommerceBuilder.DomainModel.EntityWithTypedId`1.Save() +636
test_ordernote.Page_Load(Object sender, EventArgs e) in c:\AbleMods-Modules\ReturnsManager-Gold\Site\test-ordernote.aspx.cs:17
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3064
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: a different object with the same identifier value was...

Post by jmestep » Thu May 02, 2013 4:04 am

I was getting a similar error in a routine I was using to import order items from a 7.0.2 store with custom code, but using Able's methods. John told me he had run into the same problem and found a fix, but he hasn't put his code into our SVN yet so I can look at it. It was something like flushing the session after each save.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: a different object with the same identifier value was...

Post by AbleMods » Thu May 02, 2013 6:41 am

I can't even get it to work on the first save. The above is the only code in the page.

What's weird is that it is saving the record to the table. But it's like nHibernate is firing the .Save() twice or something.

I just don't get this nHibernate.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: a different object with the same identifier value was...

Post by AbleMods » Thu May 02, 2013 7:22 am

Ok figured it out.

You have to start a new transaction and commit the transaction. No idea why, seems counter-intuitive to me. But it works.

Code: Select all

    protected void Page_Load(object sender, EventArgs e)
    {
        AbleContext.Current.Database.BeginTransaction();
        OrderNote _Note = new OrderNote();
        _Note.OrderId = 4;
        _Note.NoteType = NoteType.SystemPrivate;
        _Note.Comment = "test order note by Joe";
        _Note.UserId = AbleContext.Current.UserId;
        _Note.Save();
        AbleContext.Current.Database.CommitTransaction();
    }

Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

Post Reply