public void create(CustomerInfo customerInfo) throws PreexistingEntityException, Exception {
        if (customerInfo.getSensorInfoCollection() == null) {
            customerInfo.setSensorInfoCollection(new ArrayList<SensorInfo>());
        }
        EntityManager em = null;
        try {
            em = getEntityManager();
            em.getTransaction().begin();
            Collection<SensorInfo> attachedSensorInfoCollection = new ArrayList<SensorInfo>();
            for (SensorInfo sensorInfoCollectionSensorInfoToAttach : customerInfo.getSensorInfoCollection()) {
                sensorInfoCollectionSensorInfoToAttach = em.getReference(sensorInfoCollectionSensorInfoToAttach.getClass(), sensorInfoCollectionSensorInfoToAttach.getSensorId());
                attachedSensorInfoCollection.add(sensorInfoCollectionSensorInfoToAttach);
            }
            customerInfo.setSensorInfoCollection(attachedSensorInfoCollection);
            em.persist(customerInfo);
            for (SensorInfo sensorInfoCollectionSensorInfo : customerInfo.getSensorInfoCollection()) {
                CustomerInfo oldRelatedCustomerIdOfSensorInfoCollectionSensorInfo = sensorInfoCollectionSensorInfo.getRelatedCustomerId();
                sensorInfoCollectionSensorInfo.setRelatedCustomerId(customerInfo);
                sensorInfoCollectionSensorInfo = em.merge(sensorInfoCollectionSensorInfo);
                if (oldRelatedCustomerIdOfSensorInfoCollectionSensorInfo != null) {
                    oldRelatedCustomerIdOfSensorInfoCollectionSensorInfo.getSensorInfoCollection().remove(sensorInfoCollectionSensorInfo);
                    oldRelatedCustomerIdOfSensorInfoCollectionSensorInfo = em.merge(oldRelatedCustomerIdOfSensorInfoCollectionSensorInfo);
                }
            }
            em.getTransaction().commit();
        } catch (Exception ex) {
            if (findCustomerInfo(customerInfo.getCustomerId()) != null) {
                throw new PreexistingEntityException("CustomerInfo " + customerInfo + " already exists.", ex);
            }
            throw ex;
        } finally {
            if (em != null) {
                em.close();
            }
        }
    }