doctrine / couchdb-odm

A Document Mapper based on CouchDB
http://www.doctrine-project.org
MIT License
150 stars 53 forks source link

Uncaught exception 'Doctrine\ODM\CouchDB\Mapping\MappingException' with message is not a valid document or mapped super class. #148

Open garavito16 opened 6 years ago

garavito16 commented 6 years ago

Very good with everyone, please could you help me with this error that appears to me, already tried of everything but I do not get to solve.

Fatal error: Uncaught exception 'Doctrine\ODM\CouchDB\Mapping\MappingException' with message 'Class Documents\Article is not a valid document or mapped super class.' in C:\xampp\htdocs\CouchDoctrineODM\lib\Doctrine\ODM\CouchDB\Mapping\MappingException.php:23 Stack trace:

0 C:\xampp\htdocs\CouchDoctrineODM\lib\Doctrine\ODM\CouchDB\Mapping\Driver\AnnotationDriver.php(62): Doctrine\ODM\CouchDB\Mapping\MappingException::classIsNotAValidDocument('Documents\Artic...')

1 C:\xampp\htdocs\CouchDoctrineODM\lib\Doctrine\ODM\CouchDB\Mapping\ClassMetadataFactory.php(71): Doctrine\ODM\CouchDB\Mapping\Driver\AnnotationDriver->loadMetadataForClass('Documents\Artic...', Object(Doctrine\ODM\CouchDB\Mapping\ClassMetadata))

2 C:\xampp\htdocs\CouchDoctrineODM\lib\vendor\doctrine-common\lib\Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory.php(302): Doctrine\ODM\CouchDB\Mapping\ClassMetadataFactory->doLoadMetadata(Object(Doctrine\ODM\CouchDB\Mapping\ClassMetadata), NULL, false, Array)

3 C:\xampp\htdocs\CouchDoctrineODM\lib in C:\xampp\htdocs\CouchDoctrineODM\lib\Doctrine\ODM\CouchDB\Mapping\MappingException.php on line 23

This is my file Documents\Article.php

<?php

namespace Documents;

use Doctrine\ODM\CouchDB\Mapping\Annotations;

/ Document(indexed=true) */ class Article { /* @Id(type="string") / protected $id; / @Field(type="string") */ protected $title; / @Field(type="string", indexed=true) */ protected $slug; /* @Field(type="string") / protected $body; / @Field(type="datetime") */ protected $created;

public function __construct()
{
    $this->created = new \DateTime("now");
}

public function getId()
{
    return $this->id;
}

public function getTitle()
{
    return $this->title;
}

public function setTitle($title)
{
    $this->title = $title;
}

public function getBody()
{
    return $this->body;
}

public function setBody($body)
{
    $this->body = $body;
}

public function getCreated()
{
    return $this->created;
}

}

And this is my file boostrap.php.

<?php

require_once DIR . "/lib/vendor/doctrine-common/lib/Doctrine/Common/ClassLoader.php";

$loader = new \Doctrine\Common\ClassLoader("Doctrine\Common", DIR . "/lib/vendor/doctrine-common/lib"); $loader->register();

$loader = new \Doctrine\Common\ClassLoader("Doctrine", DIR . "/lib"); $loader->register();

$loader = new \Doctrine\Common\ClassLoader("Symfony", DIR . "/lib/vendor"); $loader->register();

$loader = new \Doctrine\Common\ClassLoader("Documents", DIR); $loader->register();

$database = "doctrine_sandbox";

$httpClient = new \Doctrine\CouchDB\HTTP\SocketClient();

// create database if not existing $resp = $httpClient->request('PUT', '/' . $database);

$reader = new \Doctrine\Common\Annotations\AnnotationReader(); $paths = DIR . "/Documents";

$metaDriver = new \Doctrine\ODM\CouchDB\Mapping\Driver\AnnotationDriver($reader, $paths);

$config = new \Doctrine\ODM\CouchDB\Configuration(); $config->setProxyDir(\sys_get_temp_dir()); $config->setMetadataDriverImpl($metaDriver); $config->newDefaultAnnotationDriver(array("/Documents")); $config->setLuceneHandlerName('_fti');

$couchClient = new \Doctrine\CouchDB\CouchDBClient($httpClient, $database);

$dm = \Doctrine\ODM\CouchDB\DocumentManager::create($couchClient, $config);

$article1 = new \Documents\Article(); $article1->setTitle("Who is John Galt?"); $article1->setBody("Find out!"); $dm->persist($article1); $dm->flush();


If you get to create the database, the error is in the mapping.