title: prePersist to check null object
body: <p>I have this class:</p>
  
  <pre><code> * @ORM\Entity
   * @ORM\HasLifecycleCallbacks()
  class Parameter{
  
      /**
      * @ORM\Column(name="id", type="integer")
      * @ORM\Id
      * @ORM\GeneratedValue(strategy="AUTO")
      */
      protected $id;
  
      /**
      * @ORM\ManyToOne(targetEntity="Project\Bundle\Entity\Anthropometry", inversedBy="parameter")
      * @ORM\JoinColumn(name="anthropometry_id", referencedColumnName="id")
      * 
      */
      protected $anthropometry;
  
      /**
       * @ORM\Column(name="data", type="string", length=255, nullable=true)
       */
      protected $data;
     ...
  
  }
  </code></pre>
  
  <p>and this:</p>
  
  <pre><code> /**
   * @ORM\Table(name="anthropometry")
   * @ORM\Entity
   */
  class Anthropometry {
  /**
   * @var integer $id
   *
   * @ORM\Column(name="id", type="integer")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  protected $id;
  
  /**
   * 
   * @ORM\OneToMany(targetEntity="Project\Bundle\Entity\Parameter", mappedBy="anthropometry", cascade={"persist"})
   * 
   */ 
  protected $parameter;
  
      ...
  }
  </code></pre>
  
  <p>In my Controller I am creating a form and validating in the same Action.
  To create the form I need instance one Parameter. But not need persist him.</p>
  
  <p>So.. when I call $em->flush I got the error:</p>
  
  <blockquote>
    <p>A new entity was found through the relationship ...</p>
  </blockquote>
  
  <p>To solve this I put cascade={"persist"} in annotation:</p>
  
  <pre><code>//Class Anthropometry
  ...
  /**
   * 
   * @ORM\OneToMany(targetEntity="Project\Bundle\Entity\Parameter", mappedBy="anthropometry", cascade={"persist"})
   * 
   */ 
  protected $parameter;
  </code></pre>
  
  <p>But now, in my Database, the parameters are being persisted with field 'Data' = NULL</p>
  
  <p>Can I check with prePersist if the field is NULL before persist?</p>
  
  <p>something like this?</p>
  
  <pre><code>//class Parameter
  /**
   * 
   * @ORM\prePersist
   */
  public function prePersist(){
      if($this-&gt;getData() == NULL){
          return false;
      }
  }
  </code></pre>
  
  <p>Thx!</p>