0

EDIT:

Yes, I know about answer Doctrine2 - "class" is not a valid entity or mapped super class but it uses deprecated methods, I am using Doctrine 2.6.2

I am always getting this error

Doctrine\ORM\Mapping\MappingException: Class "Osoba" is not a valid entity or mapped super class

I think the problem is in the $paths variable but I do not know what value should I use. Here is configuration and test file

<?php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;

require_once "vendor/autoload.php";

// database configuration parameters
$dbParams = array(
    'dbname' => 'xxx',
    'user' => 'xxx',
    'password' => 'xxx',
    'host' => 'xxx',
    'driver' => 'pdo_mysql',
    'port' => '3312'
);

$paths = array("app/models/DAO");
$isDevMode = false;

$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$entityManager = EntityManager::create($dbParams, $config);

The test file

require_once $_SERVER['DOCUMENT_ROOT'] . "/bootstrap.php";
require_once $_SERVER['DOCUMENT_ROOT'] . '/app/models/DAO/Osoba.php';

error_reporting(E_ALL ^ E_NOTICE);

$osoba = new Osoba();
$osoba->setMeno("Martin");


$entityManager->persist($osoba);
$entityManager->flush();

this is the mapped class, just part of it actually but should be enough

use \Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="osoba")
*/
class Osoba
{

    /**
     * @ORM\Column(type="string")
    */
    private $meno;

    public function getMeno()
    {
        return $this->meno;
    }

    public function setMeno($meno)
    {
        $this->meno = $meno;
    }

    /**
     * @ORM\Id
     * @ORM\Column(type="integer", name="id", nullable="false")
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    protected $id;

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

    public function setId($id)
    {
        $this->id = $id;
    }

And finally my project structure

project structure

Any help appreciated. I tested the database connection and it is OK, but the mapping seems to be incorrect but i really do not know why

hocikto
  • 871
  • 1
  • 14
  • 29
  • Possible duplicate of [Doctrine2 - "class" is not a valid entity or mapped super class](https://stackoverflow.com/questions/15099060/doctrine2-class-is-not-a-valid-entity-or-mapped-super-class) – Zeljka Apr 03 '19 at 21:13
  • @Zeljka the code in the answer is marked as deprecated, even though, yes it works – hocikto Apr 04 '19 at 18:04

0 Answers0