<?php //... private function ensureTransactionStarted() { if (!$this->transactionStarted) { $this->em->beginTransaction(); $this->transactionStarted = true; } } //...