3

I keep getting this error:

PHP Fatal error: Uncaught exception 'Doctrine\Common\Annotations\AnnotationException' with message '[Semantical Error] The annotation "@Document" in class Documents\Translation was never imported.' in /home/bmay/devel/svn/wwv/trunk/test_mongo_record/doctrine-mongodb-odm/lib/vendor/doctrine-mongodb-odm/lib/vendor/doctrine-common/lib/Doctrine/Common/Annotations/AnnotationException.php:52

Code is simple here:

namespace Documents;

/** @Document */
class Translation
{
    //private $string;
    //private $date;

    /** @String */
    private $name;

    public function setName($name) {
        $this->name = $name;
    }

}
Bryan M.
  • 33
  • 4

1 Answers1

2

The annotation usage changed in the new versions. Before you can use an annotation, Doctrine\ODM\MongoDB\Mapping\Annotations should be imported with use:

namespace Documents;

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

/** @ODM\Document */
class Translation
{
    /** @ODM\String */
    private $name;
}
meze
  • 14,975
  • 4
  • 47
  • 52
  • 2
    The above was helpful, but not the whole solution. I was following the getting started tutorial and it was missing a line: AnnotationDriver::registerAnnotationClasses(); Put it just before you create the AnnotationReader object. – Bryan M. Feb 21 '12 at 03:45