Dynamic databases and schema creation in Symfony/Doctrine
<p>I want to store database connections in a static database. On demand I want to create a new database, store the credentials in my static database and then create the schema inside the new database from existing entities. I know how to do that by using symfony's command line tool. My goal is to make it work in a service. I looked into the Doctrine docs and try to make something work:</p>

<pre><code>    $conn =$this-&gt;getDoctrine()-&gt;getConnection()-&gt;getSchemaManager()-&gt;createDatabase($dbname);
    $isDevMode = true;
    $config = Setup::createAnnotationMetadataConfiguration(array('UiCoreDbBundle/Entity'), $isDevMode);

    $conn = array(
        'driver' =&gt; 'pdo_mysql',
        'host' =&gt; '127.0.0.1',
        'user' =&gt; 'root',
        'dbname' =&gt; $dbname
    );
    $em = EntityManager::create($conn,$config);

    $tool = new SchemaTool($em);
    $classes = array(
      $em-&gt;getClassMetadata('Product')
      //...
    );

    $tool-&gt;createSchema($classes);
</code></pre>

<p>My example code does not work like i hoped it would. Doctrine can't find my entities. Can anyone give me a hint on the proper way to implement such a task?</p>