doctrine / mongodb-odm

The Official PHP MongoDB ORM/ODM
https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/
MIT License
1.09k stars 504 forks source link

Doctrine ODM annotations not being loaded #2266

Closed thisbar closed 3 years ago

thisbar commented 3 years ago

I am having an issue with an model while the others works succesfully. I am using version 2.2. I get this error:

Type: Doctrine\Common\Annotations\AnnotationException
Code: 0
Message: [Semantical Error] The annotation "@Doctrine\ODM\MongoDB\Mapping\Annotations\Document" in class CAAM\Entities\Payment was never imported. Did you maybe forget to add a "use" statement for this annotation?
File: D:\xampp\htdocs\caam\vendor\doctrine\annotations\lib\Doctrine\Common\Annotations\AnnotationException.php
Line: 39

My model is:

namespace CAAM\Entities;

use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;

/** @ODM\Document(collection="payments") */
class Payment
{}

The other models are identical and works!

thisbar commented 3 years ago

This issue was caused by Mercado Pago's SDK that uses Doctrine Annotations

malarzm commented 3 years ago

This issue was caused by Mercado Pago's SDK that uses Doctrine Annotations

This sounds like it should be reported upstream

In general if you're not using symfony bundle (or zend module) there's a setup step you need to do yourself so the annotations can be loaded, from https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/2.1/reference/introduction.html#setup

$loader = require_once('path/to/vendor/autoload.php');

AnnotationRegistry::registerLoader([$loader, 'loadClass']);

this possibly is mitigated by some newer version of doctrine/annotations, depends what you have installed.