6

In my symfony2 application, I have two database connections, I'd like to keep the entity classes seperate and therefore have one set of entity classes in one bundle and another set in another bundle. However when trying to call my bundle, its for some reason not registered as an Entity Namespace, the error is as follows:

Unknown Entity namespace alias 'AcmeStaffBundle'.
500 Internal Server Error - ORMException 

I have looked for where it sets the entity namespaces, and i've found it to be in the cached files

$e = new \Doctrine\ORM\Configuration();
$e->setEntityNamespaces(array('AcmeStoreBundle' => 'Acme\\StoreBundle\\Entity'));

How can i add this to array?

NEW EDIT:

My config.yml is as follows which should help clarify the issue:

orm:
    entity_managers:
        default:
            connection:       default
            mappings:
                AcmeStoreBundle: ~
        Foo:
            connection:       Foo
            mappings:
                AcmeFooBundle: ~

Thanks in advance

1
  • You solved your problem? Commented Jun 17, 2012 at 0:16

3 Answers 3

1

I had this exact problem while trying to use the generated CRUD forms. What finally solved the problem was adding the name of the preferred entity manager as a parameter to getEntityManager() like this:

$em = $this->getDoctrine()->getEntityManager('Foo');
Sign up to request clarification or add additional context in comments.

Comments

0

Not entirely sure what you mean by keeping your entities "separate" but if you're attempting to map one entity to two different tables in the same database I don't think that's possible as its listed as a doctrine limitation see: here.

1 Comment

Nope this isnt what i meant, what i meant was that I want to create my entity files seperate dependant on the database they are connecting to, in my config.yml i wanted to have orm: entity_managers: default: connection: default mappings: AcmeStoreBundle: ~ Foo: connection: Foo mappings: AcmeAnotherBundle: ~
0

On using multiple entity managers:

http://symfony.com/doc/master/cookbook/doctrine/multiple_entity_managers.html

http://symfony.com/doc/master/reference/configuration/doctrine.html#mapping-configuration

Take a look to the prefix parameter:

...

orm:
    auto_generate_proxy_classes: %kernel.debug%
    default_entity_manager: default
    entity_managers:
        default:
            connection: default
            mappings:
                OneBundle:
                    prefix: One\Bundle\Entity\Namespace
        other:
            connection: other # check this :p
            mappings:
                OtherBundle:
                    prefix: Other\Bundle\Entity\Namespace

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.