In the object repository I want to get an object with the given identifier or create a new one if this identifier is not used yet. My solution is to create a new object with an identifier. If possible, I will return it, if not, I want to download it. It is very bad that this is impossible, because the entitymanager is closed.
class TestRepository extends Repository { // create a new entity or load the existing one public function getEntity($pkey) { $entity = new Entity($pkey); // create a new entity and set its id to $pkey $this->getEntityManager()->persist($language); try { $this->getEntityManager()->flush(); // success if $pkey isn't used } catch (DBALException $e) { // this DBALException is catched correct // fail - load the existing one $entity = $this->find(array($pkey)); // another exception is thrown // The EntityManager is closed. } return $entity; } }
How can I open the EntityManger app?
exoon source share