0

因此,我正在使用 ofbiz fork opentaps,并且正在创建一项新服务,该服务将允许仓库运输应用程序打包特定的序列号。我几乎完成了一些事情,除了当我尝试更新订单预订时,我不断收到这个异常:

org.ofbiz.entity.GenericEntityNotFoundException:试图更新一个不存在的实体。

这是我的代码:

public static Map<String, Object> packSpecificSerialNumberedInventoryItems(DispatchContext dctx, Map<String, Object> context){
    String orderId = (String) context.get("orderId");
    String shipGroupSeqId = (String) context.get("shipGroupSeqId");
    Map<String, Object> serialNumbersMap = (Map<String, Object>) context.get("serialNumber");
    Delegator delegator = (Delegator) dctx.getDelegator();
    LocalDispatcher dispatcher = dctx.getDispatcher();
    EntityCondition condition = null;
    List<String> usedSerialsList = new ArrayList<String>();
    try {
        condition = EntityCondition.makeCondition(UtilMisc.toMap("orderId", orderId, "shipGroupSeqId", shipGroupSeqId));
        FastList<GenericValue> orderReservations = (FastList<GenericValue>) delegator.findByCondition("OrderItemShipGrpInvRes", condition, null, null, null, null);
        for(GenericValue orderReservation : orderReservations){
            GenericValue inventoryItem = orderReservation.getRelatedOne("InventoryItem");
            if(inventoryItem.get("inventoryItemTypeId").equals("SERIALIZED_INV_ITEM")){
                String[] serialNumbers = serialNumbersMap.get(inventoryItem.get("productId")).toString().replace("\r\n", "\n").split("\n");
                List<String> serialNumbersList = new ArrayList<String>();
                for(String serialNumber : serialNumbers){
                    serialNumbersList.add(serialNumber);
                }
                if(serialNumbersList.contains(inventoryItem.get("serialNumber").toString())){
                    continue;
                } else {
                    for(String serialNumberFromList : serialNumbersList){
                        if(usedSerialsList.contains(serialNumberFromList)){
                            continue;
                        } else {
                            condition = EntityCondition.makeCondition(UtilMisc.toMap("serialNumber", serialNumberFromList));
                            GenericValue itemToBePacked = delegator.findByCondition("InventoryItem", condition, null, null, null, null).get(0);
                            if(itemToBePacked.get("statusId").equals("INV_AVAILABLE")){
                                orderReservation.put("inventoryItemId", itemToBePacked.get("inventoryItemId"));
                                orderReservation.store();
                                itemToBePacked.put("statusId", "INV_PROMISED");
                                itemToBePacked.store();
                            } else {
                                condition = EntityCondition.makeCondition(UtilMisc.toMap("inventoryItemId", itemToBePacked.get("inventoryItemId")));
                                GenericValue itemToBePackedReservation = delegator.findByCondition("OrderItemShipGrpInvRes", condition, null, null, null, null).get(0);
                                orderReservation.put("inventoryItemId", itemToBePacked.get("inventoryItemId"));
                                itemToBePackedReservation.put("inventoryItemId", inventoryItem.get("inventoryProductId"));
                                orderReservation.store();
                                itemToBePackedReservation.store();
                            }
                            usedSerialsList.add(serialNumberFromList);
                            break;
                        }
                    }

                }
            } else {
                continue;
            }
        }
        Map packBulkItemsContext = dctx.getModelService("packBulkItems").makeValid(context, ModelService.IN_PARAM);
        Map packBulkItemsResult = dispatcher.runSync("packBulkItems", packBulkItemsContext);
        if (ServiceUtil.isError(packBulkItemsResult)) {
            Debug.logError(ServiceUtil.getErrorMessage(packBulkItemsResult), MODULE);
            return packBulkItemsResult;
        }
        Map<String, Object> resultMap = ServiceUtil.returnSuccess();
        return resultMap;
    } catch (GenericEntityException e) {
        e.printStackTrace();
        Map<String, Object> resultMap = ServiceUtil.returnError("There was error with the entity\n");
        return resultMap;
    } catch (GenericServiceException e) {
        e.printStackTrace();
        Map<String, Object> resultMap = ServiceUtil.returnError("There was error with the PackBulkOrder service.\n");
        return resultMap;
    }

}

这是我的堆栈跟踪:

org.ofbiz.entity.GenericEntityNotFoundException: Tried to update an entity that does not exist.
at org.ofbiz.entity.datasource.GenericDAO.singleUpdate(GenericDAO.java:285)
at org.ofbiz.entity.datasource.GenericDAO.customUpdate(GenericDAO.java:216)
at org.ofbiz.entity.datasource.GenericDAO.update(GenericDAO.java:210)
at org.ofbiz.entity.datasource.GenericHelperDAO.store(GenericHelperDAO.java:172)
at org.ofbiz.entity.GenericDelegator.store(GenericDelegator.java:1338)
at org.ofbiz.entity.GenericDelegator.store(GenericDelegator.java:1301)
at org.ofbiz.entity.GenericValue.store(GenericValue.java:130)
at org.opentaps.warehouse.shipment.packing.PackingServices.packSpecificSerialNumberedInventoryItems(PackingServices.java:120)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.ofbiz.service.engine.StandardJavaEngine.serviceInvoker(StandardJavaEngine.java:101)
at org.ofbiz.service.engine.StandardJavaEngine.runSync(StandardJavaEngine.java:58)
at org.ofbiz.service.ModelServiceReader$GenericInvokerImpl.runSync(ModelServiceReader.java:762)
at _$gen.file_58$.Users.ryan.git.opentaps.opentaps.opentaps.warehouse.servicedef.services_95$shipping_46$xml_35$packSpecificSerialNumberedInventoryItems.runSync(file:/Users/ryan/git/opentaps/opentaps/opentaps/warehouse/servicedef/services_shipping.xml#packSpecificSerialNumberedInventoryItems:63)
at org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:400)
at org.ofbiz.service.ServiceDispatcher.runSync(ServiceDispatcher.java:227)
at org.ofbiz.service.GenericDispatcher.runSync(GenericDispatcher.java:168)
at org.ofbiz.webapp.event.ServiceEventHandler.invoke(ServiceEventHandler.java:337)
at org.ofbiz.webapp.control.RequestHandler.runEvent(RequestHandler.java:640)
at org.ofbiz.webapp.control.RequestHandler.doRequest(RequestHandler.java:383)
at org.ofbiz.webapp.control.ControlServlet.doGet(ControlServlet.java:228)
at org.ofbiz.webapp.control.ControlServlet.doPost(ControlServlet.java:91)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.ofbiz.webapp.control.ContextFilter.doFilter(ContextFilter.java:270)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:555)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:695)

任何帮助将不胜感激。我在代码中设置了断点,并且实体如预期的那样在那里,我只是不明白为什么我可以检索它们但我无法更新它们。有任何想法吗?

4

1 回答 1

0

我找到了解决这个问题的方法。问题是我试图更新外键,这在 ofbiz 是不可能的。您必须先删除然后重新创建记录。

于 2015-05-14T14:59:04.643 回答