em = ResourceUtils.getEntityManager();
em.getTransaction().begin();
Experiment_Output exOutput = new Experiment_Output();
exOutput.setEx_key(experimentKey);
Experiment experiment = em.find(Experiment.class, experimentResource.getExpID());
exOutput.setExperiment(experiment);
exOutput.setExperiment_id(experiment.getExpId());
exOutput.setValue(value);
exOutput.setOutputKeyType(outputType);
exOutput.setMetadata(metadata);
if (existingOutput != null) {
existingOutput.setEx_key(experimentKey);
existingOutput.setExperiment(experiment);
existingOutput.setValue(value);
existingOutput.setExperiment_id(experiment.getExpId());
existingOutput.setOutputKeyType(outputType);
existingOutput.setMetadata(metadata);
exOutput = em.merge(existingOutput);
} else {
em.persist(exOutput);