0

I'm working on rewriting an old plain PHP bad written app with Symfony 4.4 and Doctrine 2.12. Due to the number of databases (5) and the XXL size of them (at least 50 tables per database with often more than 100 columns) I had to generate entities from reverse engineering. Here is my Doctrine configuration.

doctrine:
    dbal:
        connections:
            fire:
                url: '%env(resolve:FIRE_DATABASE_URL)%'
                driver: 'pdo_mysql'
                server_version: 'mariadb-10.6.5'
                charset: 'utf8mb4'
                default_table_options:
                    charset: 'utf8mb4'
                    collate: 'utf8mb4_general_ci'

                schema_filter: ~.*[^_to_del]$~
                options:
                    1001: true
            leclair:
                url: '%env(resolve:LECLAIR_DATABASE_URL)%'
                driver: 'pdo_mysql'
                server_version: 'mariadb-10.6.5'
                charset: 'utf8mb4'
                default_table_options:
                    charset: 'utf8mb4'
                    collate: 'utf8mb4_general_ci'

                schema_filter: ~.*[^_to_del]$~
                options:
                    1001: true
            leclair_vad:
                url: '%env(resolve:LECLAIR_VAD_DATABASE_URL)%'
                driver: 'pdo_mysql'
                server_version: 'mariadb-10.6.5'
                charset: 'utf8mb4'
                default_table_options:
                    charset: 'utf8mb4'
                    collate: 'utf8mb4_general_ci'

                schema_filter: ~.*[^_to_del]$~
                options:
                    1001: true
            leclair_int:
                url: '%env(resolve:LECLAIR_INT_DATABASE_URL)%'
                driver: 'pdo_mysql'
                server_version: 'mariadb-10.6.5'
                charset: 'utf8mb4'
                default_table_options:
                    charset: 'utf8mb4'
                    collate: 'utf8mb4_general_ci'

                schema_filter: ~.*[^_to_del]$~
                options:
                    1001: true
            leclair_mobi:
                url: '%env(resolve:LECLAIR_MOBI_DATABASE_URL)%'
                driver: 'pdo_mysql'
                server_version: 'mariadb-10.6.5'
                charset: 'utf8mb4'
                default_table_options:
                    charset: 'utf8mb4'
                    collate: 'utf8mb4_general_ci'

                schema_filter: ~.*[^_to_del]$~
                options:
                    1001: true
    orm:
        default_entity_manager: leclair
        auto_generate_proxy_classes: true
        entity_managers:
            fire:
                connection: fire
                mappings:
                    Fire:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity/Fire'
                        prefix: 'App\Entity\Fire'
                        alias: Fire
                naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
            leclair:
                connection: leclair
                mappings:
                    Leclair:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity/Leclair'
                        prefix: 'App\Entity\Leclair'
                        alias: Leclair
                naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
            leclair_vad:
                connection: leclair_vad
                mappings:
                    LeclairVad:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity/LeclairVad'
                        prefix: 'App\Entity\LeclairVad'
                        alias: LeclairVad
                naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
            leclair_int:
                connection: leclair_int
                mappings:
                    LeclairInt:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity/LeclairInt'
                        prefix: 'App\Entity\LeclairInt'
                        alias: LeclairInt
                naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
            leclair_mobi:
                connection: leclair_mobi
                mappings:
                    LeclairMobi:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity/LeclairMobi'
                        prefix: 'App\Entity\LeclairMobi'
                        alias: LeclairMobi
                naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware

The problem is that if I set a default_entity_manager Doctrine is confused with entities from the first and second namespaces (Fire and Leclair) despite I see no error in my configuration. For instance when trying to call a TblParaImp entity from 'Fire' namespace (while default_entity_manager=leclair is configured) I get errors like

[Doctrine\Persistence\Mapping\MappingException]
  The class 'App\Entity\Fire\TblParaImp' was not found in the chain configured namespaces Ap
  p\Entity\Leclair

or like

[Doctrine\Persistence\Mapping\MappingException]
  The class 'App\Entity\Leclair\TImports' was not found in the chain configured namespaces App
  \Entity\Fire

when trying to call a TImports entity from 'Leclair' namespace while default_entity_manager=fire is configured. So I wonder what I missed in my configuration. Does anybody see where the error is ? Or at least tell me how to dump/debug Doctrine mapping, I couldn't find a way to do this.

Thanks a lot for any help or information.

Cheers

arsrobota
  • 15
  • 6
  • Do your Fire and Leclair entities cross-reference each other? `bin/console doctrine:mapping:info --em=fire` will give you the basics. – Cerad Nov 21 '22 at 13:05
  • Hi Cerad, thanks for your comment. I did not mention that, indeed, but there is no relation or reference between different databases. – arsrobota Nov 21 '22 at 13:46
  • 1
    Okay. Did `doctrine:mapping:info` show anything unexpected? You probably should not be using a default entity manager in this case just to avoid any confusion. Might even make sense to add a fifth dummy connection/manager and and use it as a default just to make sure you don't have code relying on it. Maybe even going so far as to [create decorated entity managers](https://stackoverflow.com/questions/59266372/how-to-use-symfony-autowiring-with-multiple-entity-managers/59289477#59289477) for each manager. But the error message is puzzling regardless of the default em. – Cerad Nov 21 '22 at 18:29
  • @Cerad Your idea of adding a dummy em just to "confuse" Doctrine is quite ingenious, it did the trick. For information ``doctrine:mapping:info`` returns nothing wrong. I tried not to specify a default EM but Doctrine searches in the first defined one anyway. I know about about the decorated entity manager but it sounds interesting. Thank you for your help. – arsrobota Nov 23 '22 at 08:17

0 Answers0