2016-08-03 116 views
0

gerade erstellt wurde So beschäftige ich mich mit dem Fehler:StaleObjectStateException ich bin immer ein Benutzerkonto auf Update, die

Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [Domain.Entities.General.Shipping#0]

, wenn der Benutzer will, um ihre Lieferadresse in meiner Anwendung aktualisieren.

-Controller

var shippingToAdd = new Shipping 
       { 
        UserId = newUserId, 
        FirstName = model.FirstName, 
        LastName = model.LastName, 
        Address = model.ShippingStreet, 
        SteApt = model.ShippingAptSte, 
        City = model.ShippingCity, 
        State = model.ShippingState, 
        Zip = model.ShippingZip, 
        Country = shippingCountryId, 
       }; 
       UserManagerService.UpdateShipping(shippingToAdd); 

UserManagerService

public static ISession Context { get; set; } 

     public UserManagerService(ISession context) 
     { 
      Context = context; 
     } 

    public static int UpdateShipping(Shipping shipping) 
    { 
     using (ITransaction transaction = Context.BeginTransaction()) 
     { 
      Context.Update(shipping); 
      transaction.Commit(); 
      return 0; //Right Here is where StaleObjectStateException occurs 
     } 
    } 

Gibt es trotzdem, um die Sperre zu heben, kurz bevor der Commit()? Oder was ist der beste Weg, um eine Sperre im Allgemeinen zu lösen?

STACK TRACE

[StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [Domain.Entities.General.Shipping#0]]
NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session) +2548
NHibernate.Persister.Entity.AbstractEntityPersister.UpdateOrInsert(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session) +533
NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection, Object[] oldFields, Object oldVersion, Object obj, Object rowId, ISessionImplementor session) +2372
NHibernate.Action.EntityUpdateAction.Execute() +975
NHibernate.Engine.ActionQueue.Execute(IExecutable executable) +63
NHibernate.Engine.ActionQueue.ExecuteActions(IList list) +165
NHibernate.Engine.ActionQueue.ExecuteActions() +68
NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session) +451
NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)

+286 NHibernate.Impl.SessionImpl.Flush() +385 Service.Account.UserManagerService.UpdateShipping(Shipping shipping) in c:\Users\wd\Desktop\master\Service\Account\UserManagerService.cs:189
Controllers.PayPalController.PaymentWithCreditCard(CartViewModel model, IEnumerable 1 cookiecart) in c:\Users\wd\Desktop\master\Controllers\PayPalController.cs:552
Controllers.PayPalController.Continue(CartViewModel model) in c:\Users\wd\Desktop\master\Controllers\PayPalController.cs:136
lambda_method(Closure , ControllerBase , Object[]) +268
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +87
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary
2 parameters) +603
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary 2 parameters) +93
System.Web.Mvc.Async.ActionInvocation.InvokeSynchronousActionMethod() +97 System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +53
System.Web.Mvc.Async.WrappedAsyncResult
2.CallEndDelegate(IAsyncResult asyncResult) +137
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +187
System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +136

+1

Sie haben hier nicht genügend Informationen zur Verfügung gestellt. Zum Beispiel, was ist 'Context.Update (...)'? – DavidG

+0

Entschuldigung hinzugefügt es in meinem Update. – NeoSketo

+2

Immer noch nicht genug Infos, ist das vielleicht nHibernate? Wir sind nicht psychisch! – DavidG

Antwort

1

Ich verstehe nicht, warum Sie Update aufrufen(), wenn Sie ein neues Objekt hinzufügen möchten. Wollten Sie ISession.Save() oder ISession.SaveOrUpdate() verwenden?

+0

Sie haben absolut Recht .... Ich habe eine neue Instanz in ein Update übergeben. Das war das Problem. – NeoSketo