“The class ‘x’ was not found in the chain configured namespaces”

If you are getting a namespace chain error when trying to load entities with Doctrine 2 in Zend Framework 2, it is likely because as far as Doctrine is concerned the namespace your entity is in is missing.

If you’ve copied Jason Grime’s Doctrine 2 and Zend Framework 2 tutorial then you’ll notice the configuration he places in module.config.php

  'doctrine' => array(
    'driver' => array(
      __NAMESPACE__ . '_driver' => array(
        'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
        'cache' => 'array',
        'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
      'orm_default' => array(
        'drivers' => array(
        __NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'

The key thing to note here is that it will load any entities in the Entity sub-directory of whatever namespace you are currently in. That is why he adds the namespace declaration at the top (that isn’t normally required)

namespace Snowcone;

In theory you could probably hardcode the driver configuration to whichever namespace you’d like; this is just generic so you can copy-and-paste it anywhere.

Therefore if your code doesn’t work, check that

  1. You have a ‘doctrine’ configuration section in module.config.php for whichever module you’re trying to load entities for
  2. You set the namespace of module.config.php to whichever namespace that module is, so module/Snowcone/config/module.config.php will be namespace Snowcone