on 09-28-2020 5:17 PM
Hello all,
I am updating receipt values such as quantities or prices, this works perfectly in quick service mode but in table mode I am getting the following error:
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.3.v20180807-4be1041): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.apache.derby.shared.common.error.DerbySQLIntegrityConstraintViolationException: DELETE on table 'SALESITEM' caused a violation of foreign key constraint 'RDRSLSTMSSCTSLSTMS' for key (3b87aed9-d1aa-4784-890f-c4809bdad43e). The statement has been rolled back.
Error Code: 20000
Call: DELETE FROM CCO.SALESITEM WHERE (OBJECTKEY = ?)
bind => [1 parameter bound]
Query: DeleteObjectQuery(com.sap.scco.ap.pos.entity.SalesItemMetaDataEntity@d5a9eaf4)
the error occurs exactly when updating the receipt
receiptManager.updateReceipt(receipt, true);
does anyone know what happens here?
Dear josehrmatos,
could you please post the whole snippet? Where did you hook into?
Regards
Robert
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi rzieschang, thanks for answering,
this is the code snippet, I summarized it a bit to make it more understandable;
CDBSession cdbSession = CDBSessionFactory.instance.createSession();
ReceiptPosService receiptManager = ServiceFactory.INSTANCE.getOrCreateServiceInstance(ReceiptPosService.class, cdbSession);
ReceiptEntity receipt = receiptManager.findOrCreate(UserRegistry.INSTANCE.getCurrentUser(), null, true);
CalculationPosService calculationPosService = ServiceFactory.INSTANCE.getOrCreateServiceInstance(CalculationPosService.class, cdbSession);
salesItem.setQuantity(BigDecimal.valueOf(customQty).negate());
salesItem.setQuantityManuallyChanged(true);
salesItem.setUnitGrossAmount( BigDecimal.valueOf(-precioUnitario).negate() );
salesItem.setUnitPriceChanged(true);
salesItem.setMarkChanged(true);
calculationPosService.recalculateReceipt(receipt);
receiptManager.updateReceipt(receipt, true);
BroadcasterHolder.INSTANCE.getBroadcaster().broadcastPluginEventForPath("RECEIPT_REFRESH", null);
Dear josehrmatos ,
wild guess: You are hooked into a method via @PluginAt which also adds salesItems or manipulating the receipt in any way, right? If so, please don't create a new CDBSession, rather use the session from the proxy.
The exception you see is most likely because there are two session writing on the same tables.
So as an example:
@PluginAt(pluginClass = ReceiptPosService.class, method = "addSalesItemToReceipt", where = PluginAt.POSITION.AFTER)
public Object onSalesItemAdded(Object proxy, Object[] args, Object ret, StackTraceElement caller) {
List<SalesItemEntity> salesItems = (List<SalesItemEntity>) ret;
MaterialEntity material = (MaterialEntity) args[1];
// always use the db session from the ReceiptPosService instance! If you create a db session yourself when "hooked" into a
// method from ReceiptPosService and you update things that will be written to the database a table lock will likely occur.
ReceiptPosService posService = (ReceiptPosService) proxy;
CDBSession cdbSession = posService.getDbSession();
// Do stuff with the session
return salesItems
}
hth
Robert
User | Count |
---|---|
5 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.