I'm trying to persist a simple object into the database using doctrine.
Instead I'm getting string(83) "The class 'AppBundle\Entity\User' was not found in the chain configured namespaces "
What I've done:
- Pretty much followed Symfony docs on this.
- Successfully set up my Symfony Enviorment. Created database using doctrine.
- Added entity in AppBundle\Entity and generated table using Doctrine
- Added piece of code to persist my entity to db
User.php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="user")
*/
class User
{
/**
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=100)
*/
private $username;
...
DefaultController.php
...
/**
* @Route("/", name="homepage")
* @param Request $request
* @return Response
*/
public function indexAction(Request $request)
{
$manager = $this->getDoctrine()->getManager();
$user = new User();
$user->setUsername('jiro');
$user->setPassword('fantozzi');
try{
$manager->persist($user);
$manager->flush();
}catch (\Exception $exception){
var_dump($exception->getMessage());
}
return new Response("<h1>It works</h1>");
}
...
config.yml
doctrine:
dbal:
driver: pdo_mysql
host: '%database_host%'
port: '%database_port%'
dbname: '%database_name%'
user: '%database_user%'
password: '%database_password%'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
EDIT 0: ###########################################################
I've tried this directly on my local machine and it works fine It seems that I'm having some troubles with my docker environment something not being set up correctly maybe
EDIT 1: ##############################################################
I can confirm that my docker environment is correct. Still it might cause this somehow. Another detail is that my real machine is a Mac with Sierra Os (I don't think it matters but you never know).
After a little digging I found out someone else encountered this as well.
Cannot load entity: "class" was not found in the chain configured
Doctrine cannot map entity/repository namespace in chain
Long story short I changed this line in my app.php
$kernel = new AppKernel('prod', false); => $kernel = new AppKernel('prod', true);
This will enable 'debug mode'. Everything works like a charm now. Obviously the 'solution' feels very dirty and it's only temporally.
If anyone has any clue what is causing this behaviour please do tell.