title: Doctrine - Managed Entity - Fetched Entites are not managed by default
body: <p>I am using Doctrine for a typo3/cms project to enhance the power of the backend workflows.</p>
  
  <p>So i had to boot doctrine all on my own. The most part of it was quite easy and i hat no problems at all. But when it came to persisting an existing entity i struggeld. Everytime i persisted an existing entity, it was created as a new one.</p>
  
  <p>After some digging i came to the conclusion, that is not part of the "UnitOfWork" (->contains(entity) == false). If i registered it manually within this unit everything worked fine again.</p>
  
  <pre><code>$this-&gt;entityManager-&gt;getUnitOfWork()-&gt;registerManaged($page, array('uid' =&gt; $page-&gt;getUid()), array('title' =&gt; $page-&gt;getTitle()));
  </code></pre>
  
  <p>But this can't be the end of the story.. so i still  try to figure out what when wrong with my doctrine :D</p>
  
  <p>Why are my fetched entites not managed?</p>
  
  <p>This is my DoctrineLoader:</p>
  
  <pre><code>private function createEntityManager()
  {
      global $GLOBALS;
  
      $paths = array(
          MyT3Extension::rootDir() . '/Configuration/ORM'
      );
      $isDevMode = true;
      $typoDbConfig = $GLOBALS['TYPO3_CONF_VARS']['DB'];
  
      // the connection configuration
      $dbParams = array(
          'driver'   =&gt; 'pdo_mysql',
          'user'     =&gt; $typoDbConfig['username'],
          'password' =&gt; $typoDbConfig['password'],
          'dbname'   =&gt; $typoDbConfig['database'],
          'charset'  =&gt; 'utf8'
      );
  
      $config = Setup::createYAMLMetadataConfiguration($paths, $isDevMode, MyT3Extension::rootDir() . '/Cache');
      $entityManager = EntityManager::create($dbParams, $config);
  
  
      return $entityManager;
  }
  </code></pre>
  
  <p>Yml definition for orm model:</p>
  
  <pre><code>Vendor\TypoBundle\Entity\Page:
      type:  entity
      table: pages
      id: { uid: { type: integer, generator: { strategy: AUTO } } }
      fields:
          pid: { type: integer }
          title: { type: string }
          navTitle: { type: string, column: nav_title }
          doctype: { type: integer, column: doktype }
          isSiteroot: { type: boolean, column: is_siteroot }
          layout: { type: integer }
  </code></pre>
  
  <p>Example code for usuage is:</p>
  
  <pre><code>$page = $this-&gt;entityManager-&gt;getRepository('Vendor\TypoBundle\Entity\Page')-&gt;findOneBy(array());
  $page-&gt;setTitle('Test');
  $this-&gt;entityManager-&gt;persist($page);
  $this-&gt;entityManager-&gt;flush(); // will create a new record (new uid)
  </code></pre>
  
  <p>What works is sth like:</p>
  
  <pre><code>$page = $this-&gt;entityManager-&gt;getRepository('Vendor\TypoBundle\Entity\Page')-&gt;findOneBy(array());
  
  $this-&gt;entityManager-&gt;getUnitOfWork()-&gt;registerManaged(
       $page, 
       array(
           'uid' =&gt; $page-&gt;getUid()
       ), array(
           'title' =&gt; $page-&gt;getTitle()
       )
  );
  
  $page-&gt;setTitle('Test');
  $this-&gt;entityManager-&gt;persist($page);
  $this-&gt;entityManager-&gt;flush();
  </code></pre>
  
  <p>So.. i hope anyone can help me :D (i will look in the doctrine symfony bundle for a solution..)</p>