Fatal error: Cannot redeclare class Doctrine\ORM\Mapping\Annotation in vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Annotation.php on line 22 #123

Closed
ecoleman opened this Issue Jun 1, 2012 · 22 comments

Comments

Projects
None yet
@ecoleman

ecoleman commented Jun 1, 2012

Not sure what's causing this or if it's something I screwed up...

Stack trace and composer.json here:
https://gist.github.com/2854091

@schmittjoh

This comment has been minimized.

Show comment Hide comment
@schmittjoh

schmittjoh Jun 1, 2012

Owner

While this bug might be triggered by this bundle, the bug itself is not in this bundle's code. Since you are the first to report this, my guess is that it is somewhere within your set-up/autoload/bootstrap code.

Anyway, I can't help you here.

Owner

schmittjoh commented Jun 1, 2012

While this bug might be triggered by this bundle, the bug itself is not in this bundle's code. Since you are the first to report this, my guess is that it is somewhere within your set-up/autoload/bootstrap code.

Anyway, I can't help you here.

@schmittjoh schmittjoh closed this Jun 1, 2012

@ecoleman

This comment has been minimized.

Show comment Hide comment
@ecoleman

ecoleman Jun 1, 2012

Would you mind chatting over email, IRC, or anything else?

ecoleman commented Jun 1, 2012

Would you mind chatting over email, IRC, or anything else?

@michelsalib

This comment has been minimized.

Show comment Hide comment
@michelsalib

michelsalib Oct 12, 2012

Contributor

I have the same error since this commit: c263aba

Contributor

michelsalib commented Oct 12, 2012

I have the same error since this commit: c263aba

@klaussilveira

This comment has been minimized.

Show comment Hide comment
@klaussilveira

klaussilveira Oct 16, 2012

I'm having this problem too, like @michelsalib and @ecoleman. Any ideas?

I'm having this problem too, like @michelsalib and @ecoleman. Any ideas?

@ecoleman

This comment has been minimized.

Show comment Hide comment
@ecoleman

ecoleman Oct 16, 2012

@michelsalib @klaussilveira I stopped the error by making sure I wasn't serializing the Container object or other services.

@michelsalib @klaussilveira I stopped the error by making sure I wasn't serializing the Container object or other services.

@michelsalib

This comment has been minimized.

Show comment Hide comment
@michelsalib

michelsalib Oct 16, 2012

Contributor

Actually the only I am serializing such a thing would be that it tries to access the entity manager of the doctrine PersistenCollection...

Contributor

michelsalib commented Oct 16, 2012

Actually the only I am serializing such a thing would be that it tries to access the entity manager of the doctrine PersistenCollection...

@schmittjoh

This comment has been minimized.

Show comment Hide comment
@schmittjoh

schmittjoh Oct 16, 2012

Owner

This is probably an error with Doctrine's PersistentCollection, see #199

Owner

schmittjoh commented Oct 16, 2012

This is probably an error with Doctrine's PersistentCollection, see #199

@klaussilveira

This comment has been minimized.

Show comment Hide comment
@klaussilveira

klaussilveira Oct 16, 2012

So, which version of Doctrine is JMSSerializerBundle compatible with?

So, which version of Doctrine is JMSSerializerBundle compatible with?

@krolow

This comment has been minimized.

Show comment Hide comment
@krolow

krolow Oct 16, 2012

I'm having same issue here, how we should handle that, as klaus asked there is some version of doctrine that this issue does not happen?

krolow commented Oct 16, 2012

I'm having same issue here, how we should handle that, as klaus asked there is some version of doctrine that this issue does not happen?

@klaussilveira

This comment has been minimized.

Show comment Hide comment
@klaussilveira

klaussilveira Oct 16, 2012

Using an older revision of JMSSerializerBundle, before c263aba, gives: The parameter class is expected to be either a string or an object. 0.9.0 also gives this.

Using an older revision of JMSSerializerBundle, before c263aba, gives: The parameter class is expected to be either a string or an object. 0.9.0 also gives this.

@schmittjoh

This comment has been minimized.

Show comment Hide comment
@schmittjoh

schmittjoh Oct 17, 2012

Owner

I've added a patch for this. Could you test whether t works now?

Owner

schmittjoh commented Oct 17, 2012

I've added a patch for this. Could you test whether t works now?

@t0mg

This comment has been minimized.

Show comment Hide comment
@t0mg

t0mg Oct 17, 2012

The patch worked for me, thanks.

t0mg commented Oct 17, 2012

The patch worked for me, thanks.

@klaussilveira

This comment has been minimized.

Show comment Hide comment
@klaussilveira

klaussilveira Oct 17, 2012

I got a strange "Class ArrayCollection does not exist".

I got a strange "Class ArrayCollection does not exist".

@t0mg

This comment has been minimized.

Show comment Hide comment
@t0mg

t0mg Oct 17, 2012

Likewise, actually !
I get that ReflectionException at \Symfony\vendor\jms\metadata\src\Metadata\MetadataFactory.php line 112
Objects with no ArrayCollection serialize just fine.

t0mg commented Oct 17, 2012

Likewise, actually !
I get that ReflectionException at \Symfony\vendor\jms\metadata\src\Metadata\MetadataFactory.php line 112
Objects with no ArrayCollection serialize just fine.

@michelsalib

This comment has been minimized.

Show comment Hide comment
@michelsalib

michelsalib Oct 17, 2012

Contributor

Don't forget to read the associated doc here: b8d0072
Just set the type to array and it should work.

Contributor

michelsalib commented Oct 17, 2012

Don't forget to read the associated doc here: b8d0072
Just set the type to array and it should work.

@klaussilveira

This comment has been minimized.

Show comment Hide comment
@klaussilveira

klaussilveira Oct 17, 2012

I'm serializing the output of Doctrine's Query::getOneOrNullResult(). This problem occurs with an specific Entity containing an inverse ManyToMany property.

I'm serializing the output of Doctrine's Query::getOneOrNullResult(). This problem occurs with an specific Entity containing an inverse ManyToMany property.

@t0mg

This comment has been minimized.

Show comment Hide comment
@t0mg

t0mg Oct 18, 2012

thanks for opening my eyes michelsalib, documentation on minimal setup is scarce

t0mg commented Oct 18, 2012

thanks for opening my eyes michelsalib, documentation on minimal setup is scarce

@remontees

This comment has been minimized.

Show comment Hide comment
@remontees

remontees Oct 31, 2012

I've the same bug, what can I do ?

I've the same bug, what can I do ?

@maerten

This comment has been minimized.

Show comment Hide comment
@maerten

maerten Nov 4, 2012

As klaussilveira pointed out, the problem occurs when an entity contains relationships (so it has an one or more properties of type ArrayCollection)
When setting the properties to 'null' before serializing, it works fine.
So for now I will serialize all relevant properties separately and combine the serialized data manually again.

maerten commented Nov 4, 2012

As klaussilveira pointed out, the problem occurs when an entity contains relationships (so it has an one or more properties of type ArrayCollection)
When setting the properties to 'null' before serializing, it works fine.
So for now I will serialize all relevant properties separately and combine the serialized data manually again.

@mdarse

This comment has been minimized.

Show comment Hide comment
@mdarse

mdarse Nov 15, 2012

I just fixed that by adding on the property holding the ArrayCollection :

@Serializer\Type("ArrayCollection")

mdarse commented Nov 15, 2012

I just fixed that by adding on the property holding the ArrayCollection :

@Serializer\Type("ArrayCollection")
@johnkary

This comment has been minimized.

Show comment Hide comment
@johnkary

johnkary Jan 18, 2013

I was encountering this issue (error message "Cannot redeclare class Doctrine\ORM\Mapping\Annotation" etc) and it was happening because I was trying to serialize an Entity whose property was a service. I had previously had everything working well for a while, but introduced a service in my Entity as part of a refactoring, then this error message started showing up.

I've seen suggestions from other devs that when serializing objects you should start with ExclusionPolicy = "all" and only explicitly expose the properties you need. I guess I just found one reason why that's a good idea, and I'll definitely be doing that in the future.

Here's my stack trace, which has a lot of what looks like a lot like a circular reference, in case it helps anyone find this searching in the future:

[ ... truncated ... ]
PHP  23. JMS\Serializer\Serializer->serialize() /vagrant/src/Acme/HelloBundle/Response/JsonResponse.php:39
PHP  24. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/Serializer.php:125
PHP  25. JMS\Serializer\GenericSerializationVisitor->visitArray() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:136
PHP  26. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:100
PHP  27. JMS\Serializer\GenericSerializationVisitor->visitArray() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:136
PHP  28. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:100
PHP  29. JMS\Serializer\GenericSerializationVisitor->visitProperty() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:212
PHP  30. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:139
PHP  31. JMS\Serializer\GenericSerializationVisitor->visitProperty() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:212
PHP  32. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:139
PHP  33. JMS\Serializer\GenericSerializationVisitor->visitProperty() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:212
PHP  34. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:139
PHP  35. JMS\Serializer\GenericSerializationVisitor->visitProperty() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:212
PHP  36. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:139
PHP  37. JMS\Serializer\GenericSerializationVisitor->visitArray() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:136
PHP  38. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:100
PHP  39. JMS\Serializer\GenericSerializationVisitor->visitProperty() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:212
PHP  40. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:139
PHP  41. JMS\Serializer\GenericSerializationVisitor->visitArray() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:136
PHP  42. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:100
PHP  43. JMS\Serializer\GenericSerializationVisitor->visitProperty() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:212
PHP  44. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:139
PHP  45. JMS\Serializer\GenericSerializationVisitor->visitProperty() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:212
PHP  46. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:139
PHP  47. JMS\Serializer\GenericSerializationVisitor->visitArray() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:136
PHP  48. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:100
PHP  49. JMS\Serializer\GenericSerializationVisitor->visitArray() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:136
PHP  50. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:100
PHP  51. Metadata\MetadataFactory->getMetadataForClass() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:177
PHP  52. Metadata\Driver\LazyLoadingDriver->loadMetadataForClass() /vagrant/vendor/jms/metadata/src/Metadata/MetadataFactory.php:86
PHP  53. JMS\Serializer\Metadata\Driver\DoctrineTypeDriver->loadMetadataForClass() /vagrant/vendor/jms/metadata/src/Metadata/Driver/LazyLoadingDriver.php:20
PHP  54. Metadata\Driver\DriverChain->loadMetadataForClass() /vagrant/vendor/jms/serializer/src/JMS/Serializer/Metadata/Driver/DoctrineTypeDriver.php:76
PHP  55. JMS\Serializer\Metadata\Driver\AnnotationDriver->loadMetadataForClass() /vagrant/vendor/jms/metadata/src/Metadata/Driver/DriverChain.php:33
PHP  56. Doctrine\Common\Annotations\FileCacheReader->getClassAnnotations() /vagrant/vendor/jms/serializer/src/JMS/Serializer/Metadata/Driver/AnnotationDriver.php:75
PHP  57. Doctrine\Common\Annotations\AnnotationReader->getClassAnnotations() /vagrant/vendor/doctrine/common/lib/Doctrine/Common/Annotations/FileCacheReader.php:90
PHP  58. Doctrine\Common\Annotations\DocParser->parse() /vagrant/vendor/doctrine/common/lib/Doctrine/Common/Annotations/AnnotationReader.php:151
PHP  59. Doctrine\Common\Annotations\DocParser->Annotations() /vagrant/vendor/doctrine/common/lib/Doctrine/Common/Annotations/DocParser.php:297
PHP  60. Doctrine\Common\Annotations\DocParser->Annotation() /vagrant/vendor/doctrine/common/lib/Doctrine/Common/Annotations/DocParser.php:533
PHP  61. Doctrine\Common\Annotations\DocParser->classExists() /vagrant/vendor/doctrine/common/lib/Doctrine/Common/Annotations/DocParser.php:580
PHP  62. Doctrine\Common\Annotations\AnnotationRegistry::loadAnnotationClass() /vagrant/vendor/doctrine/common/lib/Doctrine/Common/Annotations/DocParser.php:384
PHP  63. call_user_func() /vagrant/vendor/doctrine/common/lib/Doctrine/Common/Annotations/AnnotationRegistry.php:133
PHP  64. Composer\Autoload\ClassLoader->loadClass() /vagrant/vendor/doctrine/common/lib/Doctrine/Common/Annotations/AnnotationRegistry.php:133
PHP  65. include() /vagrant/vendor/composer/ClassLoader.php:150

I was encountering this issue (error message "Cannot redeclare class Doctrine\ORM\Mapping\Annotation" etc) and it was happening because I was trying to serialize an Entity whose property was a service. I had previously had everything working well for a while, but introduced a service in my Entity as part of a refactoring, then this error message started showing up.

I've seen suggestions from other devs that when serializing objects you should start with ExclusionPolicy = "all" and only explicitly expose the properties you need. I guess I just found one reason why that's a good idea, and I'll definitely be doing that in the future.

Here's my stack trace, which has a lot of what looks like a lot like a circular reference, in case it helps anyone find this searching in the future:

[ ... truncated ... ]
PHP  23. JMS\Serializer\Serializer->serialize() /vagrant/src/Acme/HelloBundle/Response/JsonResponse.php:39
PHP  24. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/Serializer.php:125
PHP  25. JMS\Serializer\GenericSerializationVisitor->visitArray() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:136
PHP  26. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:100
PHP  27. JMS\Serializer\GenericSerializationVisitor->visitArray() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:136
PHP  28. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:100
PHP  29. JMS\Serializer\GenericSerializationVisitor->visitProperty() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:212
PHP  30. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:139
PHP  31. JMS\Serializer\GenericSerializationVisitor->visitProperty() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:212
PHP  32. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:139
PHP  33. JMS\Serializer\GenericSerializationVisitor->visitProperty() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:212
PHP  34. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:139
PHP  35. JMS\Serializer\GenericSerializationVisitor->visitProperty() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:212
PHP  36. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:139
PHP  37. JMS\Serializer\GenericSerializationVisitor->visitArray() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:136
PHP  38. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:100
PHP  39. JMS\Serializer\GenericSerializationVisitor->visitProperty() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:212
PHP  40. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:139
PHP  41. JMS\Serializer\GenericSerializationVisitor->visitArray() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:136
PHP  42. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:100
PHP  43. JMS\Serializer\GenericSerializationVisitor->visitProperty() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:212
PHP  44. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:139
PHP  45. JMS\Serializer\GenericSerializationVisitor->visitProperty() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:212
PHP  46. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:139
PHP  47. JMS\Serializer\GenericSerializationVisitor->visitArray() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:136
PHP  48. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:100
PHP  49. JMS\Serializer\GenericSerializationVisitor->visitArray() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:136
PHP  50. JMS\Serializer\GraphNavigator->accept() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GenericSerializationVisitor.php:100
PHP  51. Metadata\MetadataFactory->getMetadataForClass() /vagrant/vendor/jms/serializer/src/JMS/Serializer/GraphNavigator.php:177
PHP  52. Metadata\Driver\LazyLoadingDriver->loadMetadataForClass() /vagrant/vendor/jms/metadata/src/Metadata/MetadataFactory.php:86
PHP  53. JMS\Serializer\Metadata\Driver\DoctrineTypeDriver->loadMetadataForClass() /vagrant/vendor/jms/metadata/src/Metadata/Driver/LazyLoadingDriver.php:20
PHP  54. Metadata\Driver\DriverChain->loadMetadataForClass() /vagrant/vendor/jms/serializer/src/JMS/Serializer/Metadata/Driver/DoctrineTypeDriver.php:76
PHP  55. JMS\Serializer\Metadata\Driver\AnnotationDriver->loadMetadataForClass() /vagrant/vendor/jms/metadata/src/Metadata/Driver/DriverChain.php:33
PHP  56. Doctrine\Common\Annotations\FileCacheReader->getClassAnnotations() /vagrant/vendor/jms/serializer/src/JMS/Serializer/Metadata/Driver/AnnotationDriver.php:75
PHP  57. Doctrine\Common\Annotations\AnnotationReader->getClassAnnotations() /vagrant/vendor/doctrine/common/lib/Doctrine/Common/Annotations/FileCacheReader.php:90
PHP  58. Doctrine\Common\Annotations\DocParser->parse() /vagrant/vendor/doctrine/common/lib/Doctrine/Common/Annotations/AnnotationReader.php:151
PHP  59. Doctrine\Common\Annotations\DocParser->Annotations() /vagrant/vendor/doctrine/common/lib/Doctrine/Common/Annotations/DocParser.php:297
PHP  60. Doctrine\Common\Annotations\DocParser->Annotation() /vagrant/vendor/doctrine/common/lib/Doctrine/Common/Annotations/DocParser.php:533
PHP  61. Doctrine\Common\Annotations\DocParser->classExists() /vagrant/vendor/doctrine/common/lib/Doctrine/Common/Annotations/DocParser.php:580
PHP  62. Doctrine\Common\Annotations\AnnotationRegistry::loadAnnotationClass() /vagrant/vendor/doctrine/common/lib/Doctrine/Common/Annotations/DocParser.php:384
PHP  63. call_user_func() /vagrant/vendor/doctrine/common/lib/Doctrine/Common/Annotations/AnnotationRegistry.php:133
PHP  64. Composer\Autoload\ClassLoader->loadClass() /vagrant/vendor/doctrine/common/lib/Doctrine/Common/Annotations/AnnotationRegistry.php:133
PHP  65. include() /vagrant/vendor/composer/ClassLoader.php:150
@tua

This comment has been minimized.

Show comment Hide comment
@tua

tua Nov 14, 2013

It seems serializer throw expcetion when try to serialize an object which cannot be serialized. For example, when I try to serialize the Request->attributes->all(), I got such an exception.
So i guess the exception on serialize part need to improve to avoid this happen.

tua commented Nov 14, 2013

It seems serializer throw expcetion when try to serialize an object which cannot be serialized. For example, when I try to serialize the Request->attributes->all(), I got such an exception.
So i guess the exception on serialize part need to improve to avoid this happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment