Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command execution error "Cannot find the entity manager" #247

Open
jogoool opened this issue Oct 17, 2022 · 9 comments
Open

Command execution error "Cannot find the entity manager" #247

jogoool opened this issue Oct 17, 2022 · 9 comments
Labels
Status: Waiting Feedback Needs feedback from the author

Comments

@jogoool
Copy link

jogoool commented Oct 17, 2022

after installing the bundle the make:reset-password command could not generate all the files, I got error Cannot find the entity manager for class "App\Entity\ResetPasswordRequest"

P V
symfony 5.4
doctrine 2.10
PHP 8.1.11

created: src/Controller/ResetPasswordController.php
created: src/Entity/ResetPasswordRequest.php

In DoctrineHelper.php line 91:

Cannot find the entity manager for class "App\Entity\ResetPasswordRequest"

@fundo-moretti
Copy link

I had the very same problem and I think it's related to Doctrine. Annotations instead of attributes were used in entities.

I've updated project's code using Rector (see Upgrading & What's New in Symfony 6!), and now it is working as expected.

@jrushlow
Copy link
Collaborator

Howdy @jogoool, @fundo-moretti is correct - this is caused by the mapping type (annotation/attribute) that your app is using.

It sounds like you're using attributes for your entities but the ResetPasswordRequest entity does not have the correct attributes. Can you provide your ResetPasswordRequest object here and we can help you sort that out.

@jrushlow jrushlow added the Status: Waiting Feedback Needs feedback from the author label Nov 21, 2022
@HrjSnz
Copy link

HrjSnz commented Jan 27, 2023

Hello, i was just dealing with this today. And somewhere on git in issues I found that there is a problem that should be fixed. As a fix install version 1.x

image

@spetters
Copy link

spetters commented Feb 2, 2023

Do you use annotations or attributes? For me with attributes, the following works:

<?php
declare(strict_types = 1);

namespace App\Entity;

use App\Repository\ResetPasswordRequestRepository;
use Doctrine\ORM\Mapping as ORM;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestInterface;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestTrait;

#[ORM\Entity(repositoryClass: ResetPasswordRequestRepository::class)]
class ResetPasswordRequest implements ResetPasswordRequestInterface {

	use ResetPasswordRequestTrait;

	#[ORM\Id]
	#[ORM\GeneratedValue]
	#[ORM\Column(type: 'integer')]
	private int $id;

	#[ORM\ManyToOne(targetEntity: User::class)]
	#[ORM\JoinColumn(nullable: false)]
	private User $user;

...

@jeremyrncp
Copy link

I have the same error :

image

@fundo-moretti
Copy link

Well, if you have the same error, you could probably fix it by converting your entity mapping type from annotation to attribute (see above).

@jeremyrncp
Copy link

What is the good way for that ?

@fundo-moretti
Copy link

As I said, see above. I mean, read chapters 03 Automating Upgrades with Rector and 04 Post-Rector Cleanups & Tweaks of this Symfonycast Upgrading & What's New in Symfony 6!.
This will help you to automate conversion of annotations to attributes.

Here's the rector.php I used (with PHP 8.0 and Symfony 5.4):

<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Doctrine\Set\DoctrineSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Symfony\Set\SensiolabsSetList;
use Rector\Symfony\Set\SymfonyLevelSetList;
use Rector\Symfony\Set\SymfonySetList;

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->symfonyContainerXml(__DIR__ . '/var/cache/dev/App_KernelDevDebugContainer.xml');

    $rectorConfig->importNames();
    $rectorConfig->importShortClasses(false);

    $rectorConfig->sets([
        LevelSetList::UP_TO_PHP_80,
        SymfonyLevelSetList::UP_TO_SYMFONY_54,
        SymfonySetList::SYMFONY_CODE_QUALITY,
        SymfonySetList::ANNOTATIONS_TO_ATTRIBUTES,
        DoctrineSetList::ANNOTATIONS_TO_ATTRIBUTES,
        DoctrineSetList::GEDMO_ANNOTATIONS_TO_ATTRIBUTES,
        SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION,
        SensiolabsSetList::FRAMEWORK_EXTRA_61,
    ]);
};

If you don't want to use Rector, manually change annotations /** @ORM\...*/ to attributes #[ORM\...] in your entity files.

@astronati
Copy link

astronati commented Aug 21, 2023

The project totally uses attributes but I face the same issue.
Any suggestion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Waiting Feedback Needs feedback from the author
Projects
None yet
Development

No branches or pull requests

7 participants