Search code examples
phpzend-framework2doctrine

@ORM\PrePersist is not allowed to be declared on property


i have been learning zend framework for the past days now. I have encountered this error when i tried to run the site:

Annotation @ORM\PrePersist is not allowed to be declared on property Post\Entity\Post::$alterado. You may only use this annotation on these code elements: METHOD.

heres my Post.php file:

 <?php

 namespace Post\Entity;

 use Application\Entity\AbstractEntity;
 use Doctrine\ORM\Mapping as ORM;

 /**
 * Post
 *
 * @ORM\Table(name="post")
 * @ORM\Entity
 * @ORM\HasLifecycleCallbacks
 * @ORM\Entity(repositoryClass="Post\Entity\PostRepository")
 */
 class Post extends AbstractEntity
 {
 /**
 * @var integer
 * @ORM\Id
 * @ORM\Column(name="id", type="integer", nullable=false)
 */
private $id;

/**
 * @var string
 *
 * @ORM\Column(name="titulo", type="string", length=80, nullable=false)
 */
private $titulo;

/**
 * @var string
 *
 * @ORM\Column(name="descricao", type="string", length=150, nullable=false)
 */
private $descricao;

/**
 * @var string
 *
 * @ORM\Column(name="texto", type="text", nullable=false)
 */
private $texto;

/**
 * @var \DateTime
 *
 * @ORM\Column(name="cadastro", type="datetime", nullable=false)
 */
private $cadastro;

/**
 * @var \DateTime
 * @ORM\PrePersist
 * @ORM\Column(name="alterado", type="datetime", nullable=false)
 */
private $alterado;

/**
 * @var boolean
 * @ORM\PosUpdate
 * @ORM\Column(name="ativo", type="boolean", nullable=false)
 */
private $ativo = '0';

/**
 * @var \Categoria\Entity\Category
 *
 * @ORM\ManyToOne(targetEntity="Categoria\Entity\Category")
 * @ORM\JoinColumn(name="categoria_id", referencedColumnName="id")
 */
private $categoriaId;



/**
 * Set id
 *
 * @param integer $id
 *
 * @return Post
 */
public function setId($id)
{
    $this->id = $id;

    return $this;
}

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

/**
 * Set titulo
 *
 * @param string $titulo
 *
 * @return Post
 */
public function setTitulo($titulo)
{
    $this->titulo = $titulo;

    return $this;
}

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

/**
 * Set descricao
 *
 * @param string $descricao
 *
 * @return Post
 */
public function setDescricao($descricao)
{
    $this->descricao = $descricao;

    return $this;
}

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

/**
 * Set texto
 *
 * @param string $texto
 *
 * @return Post
 */
public function setTexto($texto)
{
    $this->texto = $texto;

    return $this;
}

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

/**
 * Set cadastro
 *
 * @param \DateTime $cadastro
 *
 * @return Post
 */
public function setCadastro($cadastro)
{
    $this->cadastro = $cadastro;

    return $this;
}

/**
 * Get cadastro
 *
 * @return \DateTime
 */
public function getCadastro()
{
    return $this->cadastro;
}

/**
 * Set alterado
 *
 * @param \DateTime $alterado
 *
 * @return Post
 */
public function setAlterado($alterado)
{
    $this->alterado = $alterado;

    return $this;
}

/**
 * Get alterado
 *
 * @return \DateTime
 */
public function getAlterado()
{
    return $this->alterado;
}

/**
 * Set ativo
 *
 * @param boolean $ativo
 *
 * @return Post
 */
public function setAtivo($ativo)
{
    $this->ativo = $ativo;

    return $this;
}

/**
 * Get ativo
 *
 * @return boolean
 */
public function getAtivo()
{
    return $this->ativo;
}

/**
 * Set categoriaId
 *
 * @param \Categoria\Entity\Category $categoriaId
 *
 * @return Post
 */
public function setCategoriaId(\Categoria\Entity\Category $categoriaId = null)
{
    $this->categoriaId = $categoriaId;

    return $this;
}

/**
 * Get categoriaId
 *
 * @return \Categoria\Entity\Category
 */
public function getCategoriaId()
{
    return $this->categoriaId;
}
}

Am i missing any "use" statement on the file?

Any help is apreciated, thank you for your atention :)


Solution

  • I fixed it, i should have call @ORM\PrePersist and @ORM\PosUpdate on the method. :)