The class «Entity» was not found in the chain configured namespaces in production mode #8687
-
For a project I use separate databases and entity managers using Symfony 5.2.7 and Doctrine ORM 2.8.2. My doctrine:
dbal:
connections:
myproject:
driver: 'pdo_mysql'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
override_url: true
url: '%env(resolve:DATABASE_URL_MYPROJECT)%'
orm:
auto_generate_proxy_classes: true
entity_managers:
myproject:
connection: myproject
mappings:
MyProject:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/MyProject'
prefix: 'App\Entity\MyProject'
alias: MyProject (only one database and entity manager is currently used, but this is to be extended in the future). When I try to get the repository class of an entity within a controller using $repository = $this->getDoctrine()->getRepository(Entity::class); everything is fine, regardless of in which mode Symfony runs. However, when trying to get that class from an autowired entity manager within a generic (service) class, like class Service
{
private ObjectRepository $repository;
public function __construct(EntityManagerInterface $em)
{
$this->repository = $em->getRepository(Entity::class);
}
/* … */
} Symfony outputs a 500 error when running in production mode and writes
to For the record, the service class is also autowired in the controller method: class TheController extends AbstractController
{
/* … */
public function router(string $path, Service $service): Response
/* … */
} Everything works as expected, no error is thrown or output in |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
This is not technically a Doctrine problem, because these kinds of object wiring happens in Symfony. I moved it to a support question for now. |
Beta Was this translation helpful? Give feedback.
-
You are probably running into doctrine/DoctrineBundle#1337. Make sure you define |
Beta Was this translation helpful? Give feedback.
You are probably running into doctrine/DoctrineBundle#1337. Make sure you define
entity_managers:
config in your prod/doctrine.yaml