em.close();
em = ResourceUtils.getEntityManager();
em.getTransaction().begin();
NodeOutput nodeOutput = new NodeOutput();
WorkflowNodeDetail nodeDetail = em.find(WorkflowNodeDetail.class, nodeDetailResource.getNodeInstanceId());
nodeOutput.setNode(nodeDetail);
nodeOutput.setNodeId(nodeDetail.getNodeId());
nodeOutput.setOutputKey(outputKey);
nodeOutput.setOutputKeyType(outputType);
nodeOutput.setValue(value);
nodeOutput.setMetadata(metadata);
if (existingOutput != null) {
existingOutput.setNode(nodeDetail);
existingOutput.setNodeId(nodeDetail.getNodeId());
existingOutput.setOutputKey(outputKey);
existingOutput.setOutputKeyType(outputType);
existingOutput.setValue(value);
existingOutput.setMetadata(metadata);
nodeOutput = em.merge(existingOutput);