生产时出现MappingException错误

时间:2012-02-02 11:18:29

标签: symfony

我在生产环境中收到此错误:(来自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 [] []

但在我的开发环境中,一切正常。

这是我的Curso实体:

<?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;
    }
}

正如我所说,在app_dev中工作正常。

2 个答案:

答案 0 :(得分:2)

根据您所处的环境,您可以拥有不同的元数据缓存配置。例如apc如果未正确刷新,可能会导致问题。

无论如何,你必须在prod环境中预热你的缓存,如下所示:

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

如果仍然无效,请尝试更改您的学说缓存配置:

        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

这将使用array缓存驱动程序,每次请求都会刷新一次。 您不应该在生产中使用它,但它可以帮助您了解问题的来源。

答案 1 :(得分:0)

在我的情况下,通过将我的服务器缓存从eAccelerator更改为APC来解决问题。显然,eAccelerator会删除文件中的所有注释,这会破坏您的注释。