Sylius: [Doctrine\Common\Persistence\Mapping\MappingException] Class 'Sylius\Component\Product\Model\AttributeValueInterface' does not exist

Created on 14 Oct 2015  路  13Comments  路  Source: Sylius/Sylius

Hi guys,

I try to use Sylius product bundles (0.15.* version). And receive this error:

  [Doctrine\Common\Persistence\Mapping\MappingException]
  Class 'Sylius\Component\Product\Model\AttributeValueInterface' does not exist

after i am execute php app/console doctrine:schema:validate:

[Mapping]  FAIL - The entity-class 'Sylius\Component\Product\Model\Product' mapping is invalid:
* The target entity 'Sylius\Component\Product\Model\AttributeValueInterface' specified on Sylius\Component\Product\Model\Product#attributes is unknown or not an entity.

  [Doctrine\Common\Persistence\Mapping\MappingException]
  Class 'Sylius\Component\Product\Model\AttributeValueInterface' does not exist

My composer.json:

    "require": {
        "php": ">=5.3.9",
        "symfony/symfony": "2.3.*",
        "doctrine/orm": "^2.4.8",
        "doctrine/doctrine-bundle": "~1.4",
        "symfony/assetic-bundle": "~2.3",
        "symfony/swiftmailer-bundle": "~2.3",
        "symfony/monolog-bundle": "~2.4",
        "sensio/distribution-bundle": "~4.0",
        "sensio/framework-extra-bundle": "^3.0.2",
        "incenteev/composer-parameter-handler": "~2.0",
        "sylius/product-bundle": "0.15.*"
    },

And I try to configure it:

stof_doctrine_extensions:
    orm:
        default:
            sluggable: true
            timestampable: true

sylius_product:
    classes:
        product:
            model: Sylius\Component\Product\Model\Product
            controller: Sylius\Bundle\ProductBundle\Controller\ProductController
            repository: Sylius\Bundle\ProductBundle\Doctrine\ORM\ProductRepository

sylius_archetype:
    classes:
        product:
            subject: Sylius\Component\Product\Model\Product
            attribute: Sylius\Component\Product\Model\Attribute
            option: Sylius\Component\Product\Model\Option
            archetype:
                model: Sylius\Component\Product\Model\Archetype

sylius_attribute:
    classes:
        product:
            subject: Sylius\Component\Product\Model\Product
            attribute:
                model: Sylius\Component\Product\Model\Attribute
            attribute_value:
                model: Sylius\Component\Attribute\Model\AttributeValue

sylius_variation:
    classes:
        product:
            variable: Sylius\Component\Product\Model\Product
            variant:
                model: Sylius\Component\Product\Model\Variant
                repository: Sylius\Bundle\ProductBundle\Doctrine\ORM\VariantRepository

sylius_translation:
    default_locale: %locale%

Seems like a problem with mapping AttributeValueInterface to AttributeValue model.

Potential Bug

All 13 comments

Have you tried using SyliusComponent*Product*ModelAttributeValue?

sylius_attribute:
    classes:
        product:
            subject: Sylius\Component\Product\Model\Product
            attribute:
                model: Sylius\Component\Product\Model\Attribute
            attribute_value:
                model: Sylius\Component\Product\Model\AttributeValue

@michalmarcinkowski I tried, same error received:(

I push my test example to this repository, maybe it can help to detect problem.

@DarioSwain Have you configured DoctrineBundle after Sylius bundles?

@pjedrzejewski yes, you can found it here.
I use same configuration like in CoreBundle, without bundles what i don't use now.

UPD: I try to configured DoctrineBundle before Sylius bundles - received same error.

OK, it's a bug then, we will try to reproduce and fix it on your fork maybe. :) Thank you for fast reply!

hello @pjedrzejewski @michalmarcinkowski !
I have some times to investigation and I solved this problem. I don't fully understand what is the case. I think it is related to Doctrine dynamic mapping and maybe to priority of LoadMetadataSubscriber's.

I solved this problem with moving creation of new Sylius\Bundle\ProductBundle\SyliusProductBundle() to top in my AppKernel. At now, I don't fully understand what is relation between Doctrine dynamic mapping and register bundles order. Maybe someone of you can understand more faster than I:)

My old AppKernel:

$bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new Sylius\Bundle\ResourceBundle\SyliusResourceBundle(),
            new Sylius\Bundle\ProductBundle\SyliusProductBundle(),
            new Sylius\Bundle\ArchetypeBundle\SyliusArchetypeBundle(),
            new Sylius\Bundle\AttributeBundle\SyliusAttributeBundle(),
            new Sylius\Bundle\VariationBundle\SyliusVariationBundle(),
            new Sylius\Bundle\TranslationBundle\SyliusTranslationBundle(),
            new FOS\RestBundle\FOSRestBundle(),
            new JMS\SerializerBundle\JMSSerializerBundle($this),
            new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
            new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
            new AppBundle\AppBundle(),
);

My new AppKernel:

        $bundles = array(
            new Sylius\Bundle\ProductBundle\SyliusProductBundle(),

            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new Sylius\Bundle\ResourceBundle\SyliusResourceBundle(),

            new Sylius\Bundle\ArchetypeBundle\SyliusArchetypeBundle(),
            new Sylius\Bundle\AttributeBundle\SyliusAttributeBundle(),
            new Sylius\Bundle\VariationBundle\SyliusVariationBundle(),
            new Sylius\Bundle\TranslationBundle\SyliusTranslationBundle(),
            new FOS\RestBundle\FOSRestBundle(),
            new JMS\SerializerBundle\JMSSerializerBundle($this),
            new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
            new WhiteOctober\PagerfantaBundle\WhiteOctoberPagerfantaBundle(),
            new AppBundle\AppBundle(),
);

I hope it is helpfull.
If i will have more free time I will continue my investigation.

@DarioSwain as @pjedrzejewski commented (https://github.com/Sylius/Sylius/issues/3429#issuecomment-149320341) you should register all Sylius bundles before the DoctrineBundle. That's why the new Kernel helped to resolve the issue :)

@DarioSwain Yeps, and I want to remove this requirement badly by using prepending instead of custom listener registration... Hopefully we can work on that soon. :) Please close this issue if it is resolved for now.

@michalmarcinkowski @pjedrzejewski thank you guys! Yes it is resolved.

I create a custom bundle AcmeExampleBundle, which uses SyliusResourceBundle ways,
Even though I put DoctrineBundle after this bundle , Doctrine still shows this error

[Doctrine\Common\Persistence\Mapping\MappingException]                       
  Class 'Acme\Component\Example\Model\ExampleInterface' does not exist

I have created many sylius-like bundles, no matter what I do, I can only use entity name like 'Acme\Component\Example\Model\Example in orm definition, It always shows the above error when use AcmeComponentExampleModelExampleInterface.

@videni Have you solved your problem?

@barik94, solved , thanks for asking,

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mikemix picture mikemix  路  3Comments

inssein picture inssein  路  3Comments

mezoni picture mezoni  路  3Comments

xleliberty picture xleliberty  路  3Comments

crbelaus picture crbelaus  路  3Comments