Symfony 5 multiple database connection

I would like to connect to two database in my Symfony project. I used the Symfony https://symfony.com/doc/5.0/doctrine/multiple_entity_managers.html doc to configure doctrine but when I try to see if it work with a simple dump of my table in the Controller I get a error : ORA-00942: table or view does not exist.
Here is my code :

Controller

<?php

namespace AppController;


use AppEntityCustomerAgRhu;
use SymfonyComponentRoutingAnnotationRoute;
use SymfonyBundleFrameworkBundleControllerAbstractController;

class RechercheRhuController extends AbstractController
{
    /**
     * @Route("/rhu", name="rhu")
     */
    public function index()
    {
        $rhu = $this->getDoctrine()->getRepository(AgRhu::class, 'Customer')->findAll();
        dd($rhu);
        return $this->render('recherche_rhu/rhu.html.twig', [
            'controller_name' => 'RechercheRhuController',
        ]);

    }
}

Repository

<?php

namespace AppRepository;

use AppEntityCustomerAgRhu;
use DoctrineCommonPersistenceManagerRegistry;
use DoctrineBundleDoctrineBundleRepositoryServiceEntityRepository;

/**
 * @method AgRhu|null find($id, $lockMode = null, $lockVersion = null)
 * @method AgRhu|null findOneBy(array $criteria, array $orderBy = null)
 * @method AgRhu[]    findAll()
 * @method AgRhu[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */

class AgRhuRepository extends ServiceEntityRepository 
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, AgRhu::class);
    }

    // /**
    //  * @return AgRhu[] Returns an array of AgRhu objects
    //  */
    /*
    public function findByExampleField($value)
    {
        return $this->createQueryBuilder('a')
            ->andWhere('a.exampleField = :val')
            ->setParameter('val', $value)
            ->orderBy('a.id', 'ASC')
            ->setMaxResults(10)
            ->getQuery()
            ->getResult()
        ;
    }
    */

    /*
    public function findOneBySomeField($value): ?AgRhu
    {
        return $this->createQueryBuilder('a')
            ->andWhere('a.exampleField = :val')
            ->setParameter('val', $value)
            ->getQuery()
            ->getOneOrNullResult()
        ;
    }
    */
}

Entity

<?php

namespace AppEntityCustomer;

use DoctrineORMMapping as ORM;

/**
 * AgRhu
 *
 * @ORMTable(name="AG_RHU", indexes={@ORMIndex(name="i_ag_rhu_num_adeli", columns={"RHU_NUM_ADELI"}), @ORMIndex(name="i_ag_rhu_2", columns={"RHU_NOM_MAR", "RHU_PRN"}), @ORMIndex(name="i_ag_rhu_1", columns={"RHU_NOM", "RHU_PRN"})})
 * @ORMEntity(repositoryClass= "AppRepositoryAgRhuRepository")
 */
class AgRhu
{
    /**
     * @var string
     *
     * @ORMColumn(name="RHU_NUM_MAT", type="string", length=12, nullable=false)
     * @ORMId
     * @ORMGeneratedValue(strategy="SEQUENCE")
     * @ORMSequenceGenerator(sequenceName="AG_RHU_RHU_NUM_MAT_seq", allocationSize=1, initialValue=1)
     */
    private $rhuNumMat;

    /**
     * @var string|null
     *
     * @ORMColumn(name="RHU_NUM_ADELI", type="string", length=12, nullable=true)
     */
    private $rhuNumAdeli;

    /**
     * @var string|null
     *
     * @ORMColumn(name="RHU_TIT", type="string", length=4, nullable=true)
     */
    private $rhuTit;

    /**
     * @var string|null
     *
     * @ORMColumn(name="RHU_NOM", type="string", length=35, nullable=true)
     */
    private $rhuNom;

    /**
     * @var string|null
     *
     * @ORMColumn(name="RHU_NOM_MAR", type="string", length=35, nullable=true)
     */
    private $rhuNomMar;

doctrine.yaml

doctrine:
dbal:
    default_connection:   default
    connections:
        default:
            driver:    'oci8'
            dbname:    'OTALCHR'
            servicename: ''
            service: true
            host:      ''
            port:      ''
            user:      ''
            password:  ''
            charset:   'utf8mb4'
            schema_filter: ~^(?!P026CORR_MED|CORR_SPECI_COMP|CORR_UTIL|CL_BAL_EAI|CORR_MED_ADM_EM|CORR_MED_TOUT|CORR_MED_VALIDATION|CORR_SPECI_COMP|CORR_UTIL|P026CORR_MED|P026CORR_MED_TRACE|SIB_CLV_BAL_CORR|SIB_CORR_SV|SIB_REF_IDENT)~
        Customer:
            driver:    'oci8'
            dbname:    'AG_INST_DATA'
            servicename: ''
            service: true
            host:      ''
            port:      ''
            user:      ''
            password:  ''
            charset:   'utf8mb4'
            schema_filter: ~^(?!AG_AUTORISE_PAT|AG_AUTORISE_RES|AG_CAC|AG_COMPTEURS|AG_DISPO_PAT|AG_DISPO_RES|AG_INDISPO_PAT|AG_INDISPO_RES|AG_PARAM|AG_PRESTA_CAC_RHU|AG_QUALIF_RHU|AG_RDV|AG_RDV_AEX|AG_RDV_HISTORISE|AG_RDV_PAT|AG_RDV_RES|AG_REALISE_ACT_RDV|AG_RESERVATION_PAT|AG_RHU_ETAT|AG_RMA|AG_UFO_RHU|AG_UFO_RHU_20191031|AG_UFO_RHU_20191102_OTALIA_32|AG_UFO_RMA|AG_OPTIONS)~

orm:
    default_entity_manager: default
    entity_managers:
        default:
            connection: default
            mappings:
                Main:
                    is_bundle: false
                    type: annotation
                    dir: '%kernel.project_dir%/src/Entity'
                    prefix: 'AppEntity'
                    alias: Main
        Customer:
            connection: Customer
            mappings:
                Customer:
                    is_bundle: false
                    type: annotation
                    dir: '%kernel.project_dir%/src/Entity/Customer'
                    prefix: 'AppEntityCustomer'
                    alias: Customer

Does anyone know why this is not working ?
Thanks by advance for the answer, if I’m not clear, don’t hesitate to ask

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *