logo
Welcome to our new AbleCommerce forums. As a guest, you may view the information here. To post to this forum, you must have a registered account with us, either as a new user evaluating AbleCommerce or an existing user of the application. For all questions related to the older version of Gold and earlier, please go to AbleCommerce Gold forum. Please use your AbleCommerce username and password to Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
judy at Web2Market  
#1 Posted : Thursday, May 6, 2021 12:50:47 PM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 303

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
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

Wanna join the discussion?! Login to your AbleCommerce Forums forum account. New Registrations are disabled.

shaharyar  
#2 Posted : Friday, May 7, 2021 1:30:51 AM(UTC)
shaharyar

Rank: Advanced Member

Groups: Admin, Developers, Registered, HelpDesk, Authorized User
Joined: 10/5/2018(UTC)
Posts: 704

Thanks: 5 times
Was thanked: 113 time(s) in 112 post(s)
The same code is working fine in Gold? Is this correct?

Error details and the code suggests that you are trying to add a new MOMOrderShipment assigning the OrderShipmentId
But the nHibernate is trying to update the entry in the database assuming that a record is already there with the same id but this is not the case.

More details may help understand the exact issue.
judy at Web2Market  
#3 Posted : Friday, May 7, 2021 5:42:31 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 303

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
The same code worked in Gold. Yes, I'm trying to add a new shipment to this custom table and it is not already there. I'm having to rewrite numerous sections of the code to use sql statements to insert the data to custom tables with similar issues just to get it working since the site needs it to work now.
I did a test with a custom customer table by adding an Id field and changing the mapping file accordingly and it inserted the records. I just can't do that to all the tables right now because I have to check through the code for places where objects are loaded by id, changing them to things like loading for customerId.
Thanks
PS: I inherited this from another developer who is no longer here.

Edited by user Friday, May 7, 2021 5:43:22 AM(UTC)  | Reason: Not specified

judy at Web2Market  
#4 Posted : Friday, May 7, 2021 6:01:30 AM(UTC)
judy at Web2Market

Rank: Advanced Member

Groups: Developers
Joined: 11/7/2018(UTC)
Posts: 303

Thanks: 21 times
Was thanked: 5 time(s) in 5 post(s)
Also adding- he's doing these individual inserts inside a datareader looping through recoreds from an odbc datasource.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.