doctrine/DoctrineFixturesBundle — Issue #35: DoctrineFixturesBundle fails to load multiple fixture files through different connections and so different entity managers
Author: sibok
Created: 2012-02-22 08:20:17+00:00
State: open

EDIT: Assetic has changed its path, so you can remove assetic tags from app/config/config.yml and app/config/config_dev.yml to get rid of the error.

Hi,

i'm writting this thread in order to detail the full story about what's happening to me when working with multiple connections.

I have an Oracle database which is accessed by OracleBundle through oracle connection, then i have a MySQL database which is accessed by MySQLBundle using mysql connection. Inside MySQLBundle i have an entity which tries to store, as FK, a field which belongs to another entity which resides inside OracleBundle. AFAIK it can't be done by Symfony2, but in the testing process and before linking each entity with each other, so there are no FK to link each entity, while creating the above ( http://www.2shared.com/file/2u4GhFVX/SymfonyTestCasetar.html ) "project" i noticed doctrine bundle can't manage multiple connections properly.

What's happening to me when working with multiple connections? If you download the tar.gz file you could see there is a FooBundle and a BarBundle, each one using its own connection an of course each own entity manager. Inside FooBundle there is Foo entity and inside Bar Bundle there is Bar entity, each one has each fixture to load some info to the database. The issue i'm talking about appears here when trying to load the fixtures.

**First i create both databases, each one using each own entity manage so also using each own connection:
php ./symfony doctrine:database:drop --connection="bar" --force'
php ./symfony doctrine:database:drop --connection="foo" --force'
php ./symfony doctrine:database:create --connection="bar"
php ./symfony doctrine:database:create --connection="foo"

**Then i successfully create the schema:
php ./symfony doctrine:schema:create --em="bar"
php ./symfony doctrine:schema:create --em="foo"

**And finally i try to load the fixtures which throughs me an error:
php ./symfony doctrine:fixtures:load --em="foo"
php ./symfony doctrine:fixtures:load --em="bar"

**That's the error i get, so i think Symfony has some kind of bug:
Created database for connection named bar
Created database for connection named foo
ATTENTION: This operation should not be executed in a production environment.

Creating database schema...
Database schema created successfully!
ATTENTION: This operation should not be executed in a production environment.

Creating database schema...
Database schema created successfully!
> purging database
> loading myVendor\myFooBundleBundle\DataFixtures\ORM\Foo_
> loading myVendor\myBarBundleBundle\DataFixtures\ORM\Bar_

[Doctrine\ORM\Mapping\MappingException]
Class myVendor\myBarBundleBundle\Entity\Bar is not a valid entity or mapped super class.

doctrine:fixtures:load [--fixtures[="..."]] [--append] [--em="..."] [--purge-with-truncate]

purging database
loading myVendor\myFooBundleBundle\DataFixtures\ORM\Foo_
[Doctrine\ORM\Mapping\MappingException]
Class myVendor\myFooBundleBundle\Entity\Foo is not a valid entity or mapped super class.

doctrine:fixtures:load [--fixtures[="..."]] [--append] [--em="..."] [--purge-with-truncate]

**But if i randomly remove a fixture, no matter which one, everything runs fine:
mv src/myVendor/myBarBundleBundle/DataFixtures/ORM/Bar.php /tmp/
php ./symfony doctrine:fixtures:load --em="foo"
> purging database
> loading myVendor\myFooBundleBundle\DataFixtures\ORM\Foo

**But when both fixtures exists:
mv /tmp/Bar.php src/myVendor/myBarBundleBundle/DataFixtures/ORM/
php ./symfony doctrine:fixtures:load --em="foo"
> purging database
> loading myVendor\myFooBundleBundle\DataFixtures\ORM\Foo
> loading myVendor\myBarBundleBundle\DataFixtures\ORM\Bar_

[Doctrine\ORM\Mapping\MappingException]
Class myVendor\myBarBundleBundle\Entity\Bar is not a valid entity or mapped super class.