Doctrine orm: throw-proxies throwing "Unable to instantiate custom generator"

Doctrine 2.5. When trying to create a proxy manually using

doctrine orm:generate-proxies 

an exception is thrown:

[Teaching \ ORM \ ORMException]
Unable to instantiate custom generator: MyBundle \ MyCustomGenerator

I have a custom generator that works correctly:

 /** * @ORM\Column(type="string") * @ORM\Id * @ORM\GeneratedValue(strategy="CUSTOM") * @ORM\CustomIdGenerator(class="MyBundle\MyCustomGenerator") */ protected $id; 

Also, manually creating an instance of the generator, for example

 $a = new MyBundle\MyCustomGenerator(); 

works. But for some reason, the Doctrine Console throws the above exception.

I tried to debug and check what happens.
An exception is defined in completeIdGeneratorMapping ClassMetadataFactory . I checked that $definition['class'] stores the name of my custom generator: MyBundle\MyCustomGenerator . But still, the Doctrine cannot find a class.
I think I should add the definition to cli-config.php as described in the document , with use MyBundle or use MyBundle\MyCustomGenerator , but this did not work - the same exception was thrown.

Any ideas how I can make the doctrine console aware of my user ID generator?

+4
source share
2 answers

Not sure if this will help or still needs help, but try this

@ORM \ CustomIdGenerator (class = "\ MyBundle \ MyCustomGenerator")

those. add leading slash to class definition

0
source

In my case, there were several syntax errors that prevented the class from loading correctly.

Once I resolved these issues in my custom generator class, Doctrine was able to find the class. I would expect that throwing exceptions would be a syntax error, but this did not happen, perhaps because the class was used only through annotation.

However, as you stated, you can create an instance of your class using other means, so you probably won't have the same problem as me, but maybe this can help someone else!

0
source

All Articles