Doctrine 2.5. When trying to generate proxies manually with
doctrine orm:generate-proxies
an exception is thrown:
[Doctrine\ORM\ORMException]
Can't instantiate custom generator : MyBundle\MyCustomGenerator
I have a custom generator defined which works correctly:
/**
* @ORM\Column(type="string")
* @ORM\Id
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class="MyBundle\MyCustomGenerator")
*/
protected $id;
Also, instantiating the generator manually, like
$a = new MyBundle\MyCustomGenerator();
works. But for a reason the Doctrine Console throws the above exception.
I've tried to debug and check what's going on.
The exception is defined in completeIdGeneratorMapping
of ClassMetadataFactory
. I checked that $definition['class']
stores the name of my custom generator: MyBundle\MyCustomGenerator
. But still, Doctrine can't find the class.
Thought I should add the definition to cli-config.php
as explained in the doc, with use MyBundle
or use MyBundle\MyCustomGenerator
, but it did not work - still the same exception was thrown.
Any ideas how should I make the Doctrine Console aware of my custom ID generator?
Not sure it will help or still need help, but try this
@ORM\CustomIdGenerator(class="\MyBundle\MyCustomGenerator")
ie add starting slash to class definition
In my case there were a couple of syntax errors which were preventing the class from being properly autoloaded.
Once I resolved those issues in my custom generator class then Doctrine was able to find the class. I would've expected the exception throw to be the syntax errors but it didn't, perhaps because the class was being used only via an Annotation.
However as you stated you're able to instantiate your class via other means, so you're likely not having the same issue as I was, but perhaps this could help someone else!