0

I try to build an application with symfony 3.4 that access two different databases.

https://symfony.com/doc/3.4/doctrine/multiple_entity_managers.html

In this documentation i see that i had to configure my config.yml like this:

doctrine:
  dbal:
    default_connection: default
    connections:

        default:
            driver: pdo_mysql
            host: '%database_host%'
            port: '%database_port%'
            dbname: '%database_name%'
            user: '%database_user%'
            password: '%database_password%'
            charset: UTF8

        employeedb:
            driver:   pdo_mysql
            host:     '%database_host%'
            port:     '%database_port%'
            dbname:   '%database_name2%'
            user:     '%database_user%'
            password: '%database_password%'
            charset:  UTF8

  orm:
    auto_generate_proxy_classes: "%kernel.debug%"
    default_entity_manager: default
    entity_managers:
        default:
            connection: default
            mappings:
                AppBundle:  ~
        employeedb:
            connection: employeedb
            mappings:
                EmployeeBundle:  ~

I generate a seccond bundle for EmployeeBundle. Now if i try to get values from the seccond database with a simple query it works fine:

$em = $this->getDoctrine()->getManager('employeedb'); <br/>
$RAW_QUERY = "SELECT * FROM employee";

If i try with doctrine like this i get an error (ORMException):

$employees = $this->getDoctrine()
                  ->getRepository('EmployeeBundle:Employee')
                  ->findAll();

Unknown Entity namespace alias 'EmployeeBundle'.

What is wrong with my config? Should i add something in my entity_manager employeedb?

Margok
  • 1
  • 1

1 Answers1

0

the solution is to give the name of the new entitymanager in the doctrine command:

     $results = $this->getDoctrine()
                    ->getManager('employeedb')
                    ->getRepository('EmployeeBundle:Employee')
                    ->findAll();
Margok
  • 1
  • 1