doctrine / DoctrineCouchDBBundle

Symfony Bundle for DoctrineCouchDB
http://www.doctrine-project.org
Other
49 stars 46 forks source link

The class was not found in the chain configured namespaces #26

Closed sweetguy0883 closed 11 years ago

sweetguy0883 commented 11 years ago

Hello, I am trying to use this bundle with Symfony2 version 2.2 system working for last few days but no luck. My database configuration is (I am using multiple databases) :


doctrine_couch_db:
  client:
    default_connection: default
    connections:
      default:
        dbname: test
      collections:
        dbname: database1
      signups:
        dbname: database2
      appdata:
        dbname: database3
  odm:
    default_document_manager: default
    document_managers:
      default:
        auto_mapping: true

My document class is :


// MyApp\MyBundle\Document\Testing.php
namespace MyApp\MyBundle\Document;

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

/** @Document */
class Testing
{
    /** @Id */
    private $id;

    /** @Field(type="string") */
    private $name;

    /**
     * @param field_type $id
     */
    public function setId($id)
    {
        $this->name = $id;

        return $this;
    }

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

    /**
     * @param field_type $name
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * @return the $name 
     */
    public function getName()
    {
        return $this->name;
    }
}

And my controller is :


// MyApp\MyBundle\Controller\TestController.php
namespace MyApp\MyBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

class TestController extends Controller
{

    public function testAction()
    {
        $testing = new \MyApp\MyBundle\Document\Testing();
        $testing->setId("test2");
        $testing->setName("test name 2");
        $id = $testing->getId();
        $name = $testing->getName();

        $client = $this->container->get('doctrine_couch_db.client.default_connection');
        $dm = $this->container->get('doctrine_couch_db.odm.default_document_manager');
        $dm->persist($testing);
        $dm->flush();

        return array('id' => $id, 'name' => $name);
    }
}

But my problem is, the code is working fine until I am using the $dm->persist($testing); function. But as soon as I am using it, the browser throws an error :


The class 'MyApp\MyBundle\Document\Testing' was not found in the chain configured namespaces

500 Internal Server Error - MappingException

But if I am making the connection a way around (as described in Dortrine CouchDB Documentation)


$databaseName = "test";
$documentPaths = array("MyApp\MyBundle\Documents");
$httpClient = new \Doctrine\CouchDB\HTTP\SocketClient();
$dbClient = new \Doctrine\CouchDB\CouchDBClient($httpClient, $databaseName);

$config = new \Doctrine\ODM\CouchDB\Configuration();
$metadataDriver = $config->newDefaultAnnotationDriver($documentPaths);

$config->setProxyDir(__DIR__ . "/proxies");
$config->setMetadataDriverImpl($metadataDriver);
$config->setLuceneHandlerName('_fti');

$dm = new \Doctrine\ODM\CouchDB\DocumentManager($dbClient, $config);

everything is running well. But I like the method described in this bundle as it looks neat and clean with less codes. Is there something I am missing or is it the problem with the 2.2 version. Please help.

stof commented 11 years ago

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

sweetguy0883 commented 11 years ago

Hi, Thanks for the reply. I am not still clear. Are you talking about the /* @Document / in the Testing.php class in the MyApp\MyBundle\Document folder ? Or something else? Some more hints please. @stof .

sweetguy0883 commented 11 years ago

Hi, Thanks. Got it. Renamed my Document folder to CouchdbDocument and all the files where the link was used. But still I am unable to enter the value for the _id in the database. Also, a new field is being created named as "type" with the value "MyApp.MyBundle.CouchDocument.Testing" . Any suggestions for it?

stof commented 11 years ago

type is a property used by the CouchDB ODM internally to know which class should be used to map the struct to a PHP object: https://github.com/doctrine/couchdb-odm/blob/master/lib/Doctrine/ODM/CouchDB/Mapping/MetadataResolver/DoctrineResolver.php#L32

sweetguy0883 commented 11 years ago

Hello, I had removed all the couchdb odm and the bundle from my project and installed them by composer. The previous links I found was not working but at last the links from the PackageList worked and so I went for the composer option. Now the problem has again raised. When I use

$repository = $dm->getRepository("MyApp\MyBundle\CouchDocument\User")->find($user);

It gives an error message as:

The class 'Visalyze\AdminBundle\CouchDocument\User' was not found in the chain configured namespaces 
 500 Internal Server Error - MappingException 

Also it says there is problem in

symfonyApp/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php at line 38

Why is it looking in the Common Persistance Mapping? isn't it supposed to be

symfonyApp/vendor/doctrine/couchdb-odm/lib/Doctrine/ODM/CouchDB/Mapping/MappingException.php

And if I use

$repository = $dm->getRepository("User")->find($user);

then it says

The class: User could not be found

500 Internal Server Error - MappingException

But this time the error comes from

symfonyApp/vendor/doctrine/couchdb-odm/lib/Doctrine/ODM/CouchDB/Mapping/MappingException.php at line 18

My enitity class files are in MyApp/MyBundle/CouchDocument/ . Please help... I am stuck and finding no way to come out of it.. @stof

misteio commented 9 years ago

I've find the solution here >>> http://stackoverflow.com/questions/23701144/configuring-symfony-doctrinecouchdbbundle

And it works. You must add in ODM a mapping to your bundle.

sweetguy0883 commented 9 years ago

Hello @misteio Thanks for the input. The link you provided does not relate my problem. I solved it a long ago. That link was taking about a single database and in my case, I had many different databases. For others who might be interested in this problem, if I remember correctly, I solved it just by setting the auto_mapping: false in the database configuration

erdemildiz commented 9 years ago

Hi @sweetguy0883 . I 'm beginner in symfony. I 'm using symfony with mongo db . But I'm getting this error still. Please help me ! My app/config.yml ; doctrine_mongodb: connections: default: server: mongodb://localhost:27017 options: {} default_database: test_database document_managers: default: auto_mapping: true

Controller ; $product = new Product(); $product->setName("Erdem"); $product->setAge('25'); $product->setSchool("Sakarya Üniversitesi");

    $dm = $this->get('doctrine_mongodb')->getManager();
    $dm->persist($product);
    $dm->flush();

     return new Response('Created product id '.$product->getId());
sweetguy0883 commented 9 years ago

Hello @erdemildiz . Thanks for your message. Though this was a topic with couchDb, I think this is a general problem. But can you please give a bit more details like the namespace of the files and the exact error message. Also please don't forget to check the spacing in the yml files and most importantly (the silliest one but I do it quite often) make sure that the mongoDb is running...

erdemildiz commented 9 years ago

mongoDb is running. But same error.

app/config.yml

doctrine_mongodb: connections: default: server: mongodb://localhost:27017 options: {} default_database: test_database document_managers: default: auto_mapping: false

Controller

namespace fuar\sergiBundle\Controller;

use fuar\sergiBundle\Entity\Product; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Response;

class DefaultController extends Controller { public function indexAction() { $product = new Product(); $product->setName("xxx"); $product->setAge('25'); $product->setSchool("xxxx");

    $dm = $this->get('doctrine_mongodb')->getManager();
    $dm->persist($product);
    $dm->flush();

     return new Response('Created product id '.$product->getId());
}

}

fuar/sergiBundle/Entity/Product.php

namespace fuar\sergiBundle\Entity;

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

/**

2014-11-21 11:40 GMT+02:00 sweetguy0883 notifications@github.com:

Hello @erdemildiz https://github.com/erdemildiz . Thanks for your message. Though this was a topic with couchDb, I think this is a general problem. But can you please give a bit more details like the namespace of the files. Also please don't forget to check the spacing in the yml files and most importantly (the silliest one but I do it quite often) make sure that the mongoDb is running...

— Reply to this email directly or view it on GitHub https://github.com/doctrine/DoctrineCouchDBBundle/issues/26#issuecomment-63946645 .

sweetguy0883 commented 9 years ago

Did you install via composer as in http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html ?

Then you have to put your mapping files in Document folder and not in the Entity folder. This folder naming made me cry a few days. Also. when you have single database, it is better to have auto_mapping to be true.

erdemildiz commented 9 years ago

Yes . it install with composer and changing auto_mapping :true. :( Same error again

2014-11-21 11:49 GMT+02:00 sweetguy0883 notifications@github.com:

Did you install via composer as in http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html ?

Then you have to put your mapping files in Document folder and not in the Entity folder. This folder naming made me cry a few days. Also. when you have single database, it is better to have auto_mapping to be true.

— Reply to this email directly or view it on GitHub https://github.com/doctrine/DoctrineCouchDBBundle/issues/26#issuecomment-63947662 .

erdemildiz commented 9 years ago

I follow the instructions in http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html . But this error

2014-11-21 11:52 GMT+02:00 erdem ıldız erdemildiz@gmail.com:

Yes . it install with composer and changing auto_mapping :true. :( Same error again

2014-11-21 11:49 GMT+02:00 sweetguy0883 notifications@github.com:

Did you install via composer as in http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html ?

Then you have to put your mapping files in Document folder and not in the Entity folder. This folder naming made me cry a few days. Also. when you have single database, it is better to have auto_mapping to be true.

— Reply to this email directly or view it on GitHub https://github.com/doctrine/DoctrineCouchDBBundle/issues/26#issuecomment-63947662 .

sweetguy0883 commented 9 years ago

Did you rename the folder where the mapping files (Product.php) resides? If not then please rename the "Entity" folder to be "Document". They have some problem with specific naming.... also don't forget to clear the cache from the console and the browser cache too.

erdemildiz commented 9 years ago

Where is this folder . Idont find it. Web error is this;

2014-11-21 12:05 GMT+02:00 sweetguy0883 notifications@github.com:

Did you rename the folder where the mapping files (Product.php) resides? If not then please rename the "Entity" folder to be "Document". They have some problem with specific naming.... also don't forget to clear the cache from the console and the browser cache too.

— Reply to this email directly or view it on GitHub https://github.com/doctrine/DoctrineCouchDBBundle/issues/26#issuecomment-63949582 .

sweetguy0883 commented 9 years ago

I can't see your error...

The folder is inside your bundle, check in your controller, where you define your class to be (fuar\sergiBundle\Entity) but this class should be in (fuar\sergiBundle\Document)

Also check your Product class properly. You define things as "@var integer" or "@var string" but check the documentation properly... it says "@MongoDB\Id" or "@MongoDB\String". And the class should be defined as "@MongoDB\Document" and not the class name ("Product" as you have defined). This declarations are very important and without this the mapping of the database cannot work.

erdemildiz commented 9 years ago

FIRST ERROR

erdemildiz@ERDEMILDIZ /C/xampp/htdocs/symfony $ php app/console cache:clear --env=prod Clearing the cache for the prod environment with debug false

[Doctrine\Common\Persistence\Mapping\MappingException] Class 'fuar\sergiBundle\Entity\Product' does not exist

cache:clear [--no-warmup] [--no-optional-warmers]

I DIDNT FINT "Doctrine\Common\Persistence\Mapping\MappingExceptio"

SECOND ERROR

Class fuar\sergiBundle\Document\Product is not a valid document or mapped super class. 500 Internal Server Error - MappingException

PLEASE HELP ME

2014-11-21 12:38 GMT+02:00 sweetguy0883 notifications@github.com:

I can't see your error...

The folder is inside your bundle, check in your controller, where you define your class to be (fuar\sergiBundle\Entity) but this class should be in (fuar\sergiBundle\Document)

Also check your Product class properly. You define things as "@var https://github.com/var integer" or "@var https://github.com/var string" but check the documentation properly... it says "@MongoDB https://github.com/MongoDB\Id" or "@MongoDB https://github.com/MongoDB \String". And the class should be defined as "@MongoDB https://github.com/MongoDB\Document" and not the class name ("Product" as you have defined). This declarations are very important and without this the mapping of the database cannot work.

— Reply to this email directly or view it on GitHub https://github.com/doctrine/DoctrineCouchDBBundle/issues/26#issuecomment-63953522 .

sweetguy0883 commented 9 years ago
  1. For clearing the cache on prod env with debug false your need
    
    $ php app/console cache:clear --env=prod --no-debug
    
  2. I would recommend you to try and work with the dev env when you are in creating new things. Normally the bottom toolbar in the page means you are in dev env. In such case use
    
    $ php app/console cache:clear
    
  3. You have a lot of mistakes in your mapping as I mentioned earlier
    
    Also check your Product class properly. You define things as "@var integer" or "@var string" but check the documentation properly... it says "@MongoDB\Id" or "@MongoDB\String".
    And the class should be defined as "@MongoDB\Document" and not the class name ("Product" as you have defined). This declarations are very important and without this the mapping of the database cannot work.
    

    You are defining the mapping as referred by MongoDb but you are not following its specific rules... You must keep an eye on this.

42aroger commented 9 years ago

Hi, I have exactly the same problem with mongodb No Entity folder, only Document one I use correct syntax for class declaration But still the same problem... (symfony 2 mongodb)

http://stackoverflow.com/questions/27299657/mongodb-class-document-not-exist-symfony-2

diderson commented 9 years ago

@sweetguy0883 please adivises how you solve it... cause I have set 'auto_mapping: false' in a config but it still not working for me: $cat = $dm->getRepository("MyBundle\CouchDocument\PlaceCategory")->find($catId);

the error: The class 'MyBundle\CouchDocument\PlaceCategory' was not found in the chain configured namespaces

stiffroy commented 9 years ago

@diderson Make sure about a few things and please write it here.

  1. Which package are you using (couchdb-odm or couchdb-odm-bundle)? They have different mapping instructions.
  2. What about the folder structure and namespace?
  3. Which editor are you using (with phpStorm or Net Beans you get a code correcting option)
  4. How does the structure of the PlaceCategory class look like? Regards....
stiffroy commented 9 years ago

@42aroger Sorry for my late reply. Could you solve your problem? I somehow overlooked your comment. Are you sure you are using monogodb-odm-bundle and not mongodb-odm? The stackoverflow code, it looks to be working.

diderson commented 9 years ago

@stiffroy I am using couchdb-odm-bundle but both are installed: (couchdb-odm and couchdb-odm-bundle actually I did manage to get this working by changing my config file to:

doctrine_couch_db:
    client:
        dbname:               mydbname
        host:                 localhost
        port:                 5984
        user:                 null
        password:             null
        ip:                   null
        logging:              false

    odm:
        document_managers:
            default:
                mappings:
                    myBundle:
                        type: annotation
                auto_mapping: false