public void create(AlarmInfo alarmInfo) throws PreexistingEntityException, Exception {
        EntityManager em = null;
        try {
            em = getEntityManager();
            em.getTransaction().begin();
            SensorInfo relatedSensorId = alarmInfo.getRelatedSensorId();
            if (relatedSensorId != null) {
                relatedSensorId = em.getReference(relatedSensorId.getClass(), relatedSensorId.getSensorId());
                alarmInfo.setRelatedSensorId(relatedSensorId);
            }
            em.persist(alarmInfo);
            if (relatedSensorId != null) {
                relatedSensorId.getAlarmInfoCollection().add(alarmInfo);
                relatedSensorId = em.merge(relatedSensorId);
            }
            em.getTransaction().commit();
        } catch (Exception ex) {
            if (findAlarmInfo(alarmInfo.getSerialNumber()) != null) {
                throw new PreexistingEntityException("AlarmInfo " + alarmInfo + " already exists.", ex);
            }
            throw ex;
        } finally {
            if (em != null) {
                em.close();
            }
        }
    }