code: @Transactional
      public void save(E entity) {
          checkNotNull(entity, "The entity to save cannot be null");
  
          // creation with auto generated id
          if (!entity.isIdSet()) {
              entityManager.persist(entity);
              return;
          }
  
          // creation with manually assigned key
          if (jpaUtil.isEntityIdManuallyAssigned(type) && !entityManager.contains(entity)) {
              entityManager.persist(entity);
              return;
          }
          // other cases are update
          // the simple fact to invoke this method, from a service method annotated with @Transactional,
          // does the job (assuming the give entity is present in the persistence context)
      }
docs: Save or update the given entity E to the repository. Assume that the entity is already present in the persistence context. No merge is done.
  
  @param entity the entity to be saved or updated.