CouchDb Symfony2 中的映射实体

Mapping Entity in CouchDb Symfony2

我在 symfony 2.7.2 中使用 couchDb。

我有几个疑问。 现在我安装了这个 Bundle

然后我创建了一个用于测试的实体

<?php

namespace foo\GarageBundle\Document;

use Doctrine\ODM\CouchDB\Mapping\Annotations as CouchDB;

/**
 * @CouchDB\Document
 */
class Utente
{

    /** @CouchDB\Id */
    private $id;

    /** @CouchDB\Field(type="string") */
    private $nome;


    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set nome
     *
     * @param string $nome
     * @return Utente
     */
    public function setNome($nome)
    {
        $this->nome = $nome;

        return $this;
    }

    /**
     * Get nome
     *
     * @return string
     */
    public function getNome()
    {
        return $this->nome;
    }
}

在我的控制器中我添加了这段代码

    $dm = $this->container->get('doctrine_couchdb.client.default_connection');
    $doc = $this->container->get('doctrine_couchdb.odm.default_document_manager');

    try{
        $dm->createDatabase($dm->getDatabase());
    }catch(\Exception $e){
        $msg = $e->getMessage();
    }

    $user = new Utente();
    $user->setNome('foo');
    $doc->persist($user);
    $doc->flush();

我的config.yml是

doctrine_couch_db:
  client:
    default_connection: default
    connections:
        default:
            dbname: symfony2
  odm:
    default_document_manager: default
    document_managers:
        default:
            auto_mapping: true

我使用控制器创建了数据库,但无法插入新文档,出现此错误

The class 'foo\GarageBundle\Document\Utente' was not found in the chain configured namespaces

而且我不明白为什么像我现在使用的那样使用捆绑包很有用(我知道这可能是一个愚蠢的问题),以及为什么我必须使用 * @CouchDB\Document 而不是 @Document 在我的实体中 ?

似乎是与实体 class 的命名空间相关的问题。

The automapping is registering the CouchDocument subnamespace of your bundle, not Document (which is auto-mapped by DoctrineMongoDBBundle)

因此,为 User class 和您使用的其他 Counch 使用不同的命名空间,如下所示:

namespace foo\GarageBundle\CouchDocument;

特别是:

<?php

namespace foo\GarageBundle\CouchDocument;

use Doctrine\ODM\CouchDB\Mapping\Annotations as CouchDB;

/**
 * @CouchDB\Document
 */
class Utente
{

希望对您有所帮助

参见 this discussion on github

/**
 * @CouchDB\Document
 * @CouchDB\Index
 */
class Utente
{