public SoPhongVanBanNoiBo updateImpl(
      com.sgs.portlet.sovanbannoibo.model.SoPhongVanBanNoiBo soPhongVanBanNoiBo, boolean merge)
      throws SystemException {
    Session session = null;

    try {
      session = openSession();

      if (merge) {
        session.merge(soPhongVanBanNoiBo);
      } else {
        if (soPhongVanBanNoiBo.isNew()) {
          session.save(soPhongVanBanNoiBo);
        }
      }

      session.flush();

      soPhongVanBanNoiBo.setNew(false);

      return soPhongVanBanNoiBo;
    } catch (Exception e) {
      throw processException(e);
    } finally {
      closeSession(session);

      FinderCacheUtil.clearCache(SoPhongVanBanNoiBo.class.getName());
    }
  }
  /**
   * Add, update, or merge, the entity. This method also calls the model listeners to trigger the
   * proper events associated with adding, deleting, or updating an entity.
   *
   * @param soPhongVanBanNoiBo the entity to add, update, or merge
   * @param merge boolean value for whether to merge the entity. The default value is false. Setting
   *     merge to true is more expensive and should only be true when soPhongVanBanNoiBo is
   *     transient. See LEP-5473 for a detailed discussion of this method.
   * @return true if the portlet can be displayed via Ajax
   */
  public SoPhongVanBanNoiBo update(SoPhongVanBanNoiBo soPhongVanBanNoiBo, boolean merge)
      throws SystemException {
    boolean isNew = soPhongVanBanNoiBo.isNew();

    if (_listeners.length > 0) {
      for (ModelListener listener : _listeners) {
        if (isNew) {
          listener.onBeforeCreate(soPhongVanBanNoiBo);
        } else {
          listener.onBeforeUpdate(soPhongVanBanNoiBo);
        }
      }
    }

    soPhongVanBanNoiBo = updateImpl(soPhongVanBanNoiBo, merge);

    if (_listeners.length > 0) {
      for (ModelListener listener : _listeners) {
        if (isNew) {
          listener.onAfterCreate(soPhongVanBanNoiBo);
        } else {
          listener.onAfterUpdate(soPhongVanBanNoiBo);
        }
      }
    }

    return soPhongVanBanNoiBo;
  }