List<Device> results = query.getResultList();
if (results.isEmpty()) {
entityManager.getTransaction().begin();
try {
Device tmp_device = entityManager.find(Device.class, device.getId());
tmp_device.setName(device.getName());
tmp_device.setUniqueId(device.getUniqueId());
entityManager.getTransaction().commit();
return tmp_device;
} catch (RuntimeException e) {
entityManager.getTransaction().rollback();
throw e;