We have a plugin where new items are not getting added to the database like they were in Gold.
The mapping file is
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="W2M.MOMData.Orders.MOMOrderShipment,W2M_MOMData" table="W2M_MOMCustomers_Shipments" dynamic-update="true">
<id name="OrderShipmentId">
<generator class="foreign" >
<param name="property">OrderShipment</param>
</generator>
</id>
<one-to-one name="OrderShipment" constrained="true" foreign-key="none" class="CommerceBuilder.Orders.OrderShipment,CommerceBuilder" cascade="delete"/>
<property name="BoxId" />
<property name="MOMOrderNumber" />
<property name="OrderId" />
</class>
</hibernate-mapping>
The line of code is
if (custShipment == null) custShipment = new MOMOrderShipment();
custShipment.OrderShipmentId = shipment.Id;
custShipment.OrderId = vars.AC_OrderID;
custShipment.MOMOrderNumber = vars.MOM_OrderNumber;
if (boxId > 0) custShipment.BoxId = boxId;
ACdatabase.BeginTransaction();
momShipmentRepo.Save(custShipment);
ACdatabase.CommitTransaction();
(I added the transaction wrapping hoping it would help.
The error is
Exception: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [W2M.MOMData.Orders.MOMOrderShipment#739606] Stack Trace: at 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) at 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) at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection, Object[] oldFields, Object oldVersion, Object obj, Object rowId, ISessionImplementor session) at NHibernate.Action.EntityUpdateAction.Execute() at NHibernate.Engine.ActionQueue.Execute(IExecutable executable) at NHibernate.Engine.ActionQueue.ExecuteActions(IList list) at NHibernate.Engine.ActionQueue.ExecuteActions() at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session) at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event) at NHibernate.Impl.SessionImpl.Flush() at NHibernate.Impl.SessionImpl.FlushBeforeTransactionCompletion() at NHibernate.Impl.SessionImpl.BeforeTransactionCompletion(ITransaction tx) at NHibernate.Transaction.AdoTransaction.Commit() at CommerceBuilder.Common.DatabaseSessionManager.CommitTransaction(Boolean ignoreNoTransactionError) at CommerceBuilder.Common.DatabaseSessionManager.CommitTransaction() at Web2Market.MOMCustomers.UpdateOrder.Execute() in E:\1W2MBitButcket\AC9Plugins\MOMCS\W2M_MOMCS\Source\UpdateOrder.cs:line 139 at Web2Market.MOMCustomers.MOMCustomerImportManager.Import(MOMCustomerImportOptions importOptions) in E:\1W2MBitButcket\AC9Plugins\MOMCS\W2M_MOMCS\Source\MOMCustomerImportManager.cs:line 213
Has something changed in AC9? I had a couple of other plugins where I had a similar mapping file with the key being ProductId and the generator class was foreign. I had to add an identity field Id to the table to get them to work, if I remember correctly.
Thanks