code: public Subscription insertOrUpdate(Subscription subscription) {
          EntityManager entityManager = getEntityManager();
          EntityTransaction entityTransaction = null;
  
          try {
              entityTransaction = entityManager.getTransaction();
              entityTransaction.begin();
  			Subscription persistedSubscription;
  			if (subscription.getId() == null) {
  				entityManager.persist(subscription);
  				persistedSubscription = subscription;
  			} else {
  				persistedSubscription = entityManager.merge(subscription);
  			}
  			entityManager.flush();
              entityTransaction.commit();
              return persistedSubscription;
          } catch (Exception e) {
              if (entityTransaction != null && entityTransaction.isActive()) {
                  entityTransaction.rollback();
              }
              throw e;
  		} finally {
  			entityManager.close();
  		}
  	}
docs: insertOrUpdate
  
  @param subscription
  @return