Error de MappingException en producción

I'm getting this error on my production environnent: (from prod.log)

[2012-01-30 17:00:51] request.CRITICAL: Doctrine\ORM\Mapping\MappingException: Class Gitek\UdaBundle\Entity\Curso is not a valid entity or mapped super class. (uncaught exception) at /home/uda/shared/vendor/doctrine/lib/Doctrine/ORM/Mapping/MappingException.php line 142 [] []

But in my development environnent everything works fine.

And this is my Curso entity:

<?php

namespace Gitek\UdaBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
 * Gitek\UdaBundle\Entity\Curso
 *
 * @ORM\Table(name="Curso")
 * @ORM\HasLifecycleCallbacks
 * @ORM\Entity(repositoryClass="Gitek\UdaBundle\Entity\CursoRepository")
 */
class Curso
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string $nombre
     *
     * @ORM\Column(name="nombre", type="string", length=255)
     */
    private $nombre;

    /**
     * @var string $version
     *
     * @ORM\Column(name="version", type="string", length=255, nullable=true)
     */
    private $version;

    /**
     * @var integer $orden
     *
     * @ORM\Column(name="orden", type="integer", nullable=true, nullable=true)
     */
    private $orden;

    /**
     * @var integer $tiempo
     *
     * @ORM\Column(name="tiempo", type="integer", nullable=true, nullable=true)
     */
    private $tiempo;

    /**
     * @ORM\OneToMany(targetEntity="Detcurso", mappedBy="curso", cascade={"remove"})
     * @ORM\OrderBy({"orden" = "ASC"})
     */
    private $detcursos;

    /**
     * @ORM\OneToMany(targetEntity="Historial", mappedBy="curso", cascade={"remove"})
     */
    private $historiales;

    /**
     * @ORM\Column(type="datetime")
     */
    protected $created;

    /**
     * @ORM\Column(type="datetime")
     */
    protected $updated;


    public function __construct()
    {
        $this->detcursos = new \Doctrine\Common\Collections\ArrayCollection();
                $this->setCreated(new \DateTime());
        $this->setUpdated(new \DateTime());
    }

    public function __toString()
    {
        return $this->getNombre();
    }



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

    /**
     * Set nombre
     *
     * @param string $nombre
     */
    public function setNombre($nombre)
    {
        $this->nombre = $nombre;
    }

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

    /**
     * Set version
     *
     * @param string $version
     */
    public function setVersion($version)
    {
        $this->version = $version;
    }

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

    /**
     * Set orden
     *
     * @param integer $orden
     */
    public function setOrden($orden)
    {
        $this->orden = $orden;
    }

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

    /**
     * Set created
     *
     * @param datetime $created
     */
    public function setCreated($created)
    {
        $this->created = $created;
    }

    /**
     * Get created
     *
     * @return datetime 
     */
    public function getCreated()
    {
        return $this->created;
    }

    /**
     * Set updated
     *
     * @param datetime $updated
     */
    public function setUpdated($updated)
    {
        $this->updated = $updated;
    }

    /**
     * Get updated
     *
     * @return datetime 
     */
    public function getUpdated()
    {
        return $this->updated;
    }

    /**
     * Add detcursos
     *
     * @param Gitek\UdaBundle\Entity\Detcurso $detcursos
     */
    public function addDetcurso(\Gitek\UdaBundle\Entity\Detcurso $detcursos)
    {
        $this->detcursos[] = $detcursos;
    }

    /**
     * Get detcursos
     *
     * @return Doctrine\Common\Collections\Collection 
     */
    public function getDetcursos()
    {
        return $this->detcursos;
    }

    /**
     * Add historiales
     *
     * @param Gitek\UdaBundle\Entity\Historial $historiales
     */
    public function addHistorial(\Gitek\UdaBundle\Entity\Historial $historiales)
    {
        $this->historiales[] = $historiales;
    }

    /**
     * Get historiales
     *
     * @return Doctrine\Common\Collections\Collection 
     */
    public function getHistoriales()
    {
        return $this->historiales;
    }

    /**
     * Get historial
     *
     * @return Doctrine\Common\Collections\Collection 
     */
    public function getHistorial()
    {
        return $this->historial;
    }

    /**
     * Set tiempo
     *
     * @param integer $tiempo
     */
    public function setTiempo($tiempo)
    {
        $this->tiempo = $tiempo;
    }

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

As I said, in app_dev works correctly.

preguntado el 02 de febrero de 12 a las 11:02

2 Respuestas

You can have different metadata cache configurations depending on which environment you are in. For example apc can cause troubles if not correctly refreshed.

Anyway, you will have to warmup your cache in prod environment, like this:

php app/console cache:clear --env=prod

If this still doesn't work, try to change your doctrine cache configuration:

        orm:
            auto_generate_proxy_classes:    false
            default_entity_manager:         default
            entity_managers:
                default:
                    metadata_cache_driver:          array
                    query_cache_driver:             array
                    result_cache_driver:            array

Esto usará el array cache driver, which is refreshed once at every request. You shouldn't use this in production, but it can help you to understand where you problem comes from.

Respondido 02 Feb 12, 21:02

Thanks for the clue. The configuration that actually works in my app is that (config_prod.yml): doctrine: orm: auto_mapping: true auto_generate_proxy_classes: false proxy_namespace: Proxies proxy_dir: %kernel.cache_dir%/doctrine/orm/Proxies default_entity_manager: default metadata_cache_driver: array query_cache_driver: array result_cache_driver: array - Kioko Kiaza

In my case the problem was solved by changing my servers cache from eAccelerator to APC. Apparently eAccelerator strips all the comments from files which breaks your annotations.

Respondido 17 Jul 12, 23:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.