protected function endTransaction($commit) {
    $tx = $this->getPersistenceFacade()->getTransaction();
    if ($this->startedTransaction && $tx->isActive()) {
      if ($commit) {
        $tx->commit();
      }
      else {
        $tx->rollback();
      }
    }
    $this->startedTransaction = false;
  }