code: public T merge(T entity) {
          try {
              tx.begin();
              T mergedEntity = repository.merge(entity);
              loadGraph(mergedEntity);
              // we do not want to propagate any pending modification
              repository.detach(mergedEntity);
              tx.rollback();
              return mergedEntity;
          } catch (NotSupportedException nse) {
              try {
                  tx.rollback();
              } catch (Exception x) {
              }
              System.out.println("==============> TODO: handle properly " + nse.getMessage());
          } catch (SystemException se) {
              try {
                  tx.rollback();
              } catch (Exception x) {
              }
              System.out.println("==============> TODO: handle properly " + se.getMessage());
          }
          return entity;
      }
docs: /*
  Merge the passed entity in order to attach it to the current persistent context,
  then load its graph. Once done, detach it and rollback the transaction to avoid the propagation
  to the database of any pending modification. This could be considered as a _HACK_ but it does the job.