title: doctrine one to one persist id automatically with annotations
body: <p>I have a difficulty which I can't seem to resolve even though it seems I am applying the good recipes other found.</p>
  
  <p>I receive the following error : </p>
  
  <blockquote>
    <p>Entity of type AppBundle\Entity\User\Student is missing an assigned ID
    for field 'user'. The identifier generation strategy for this entity
    requires the ID field to be populated before EntityManager#persist()
    is called. If you want automatically generated identifiers instead you
    need to adjust the metadata mapping accordingly.</p>
  </blockquote>
  
  <p>I have a doctrine 2 one to one relationship between my entities user and student in symfony 2 and as I persist the user with a subform of student, i would like the id of the student to be automatically set to the id of the user.</p>
  
  <p>I have two classes :</p>
  
  <pre><code>class Student
  {
      /**
       * @ORM\Id
       * @ORM\Column(type="integer", length=11)
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      protected $id;
  
      /**
       * @ORM\Id
       * @ORM\OneToOne(targetEntity="\AppBundle\Entity\User\User", inversedBy="student")
       * @ORM\JoinColumn(name="id", referencedColumnName="id", nullable=false, unique=true, onDelete="cascade")
       */
      private $user;
  ...
  }
  
  
  class User
  {
  
      /**
       * @ORM\OneToOne(targetEntity="\AppBundle\Entity\User\Student", mappedBy="user", cascade={"persist"})
       */
      private $student;
  }
  </code></pre>
  
  <p>when I persist the entity, I have the error described above. If I call</p>
  
  <blockquote>
    <p>$entity->getStudent()->setUser($entity);</p>
  </blockquote>
  
  <p>before I persist the entity, it's just fine, I get the student persisted with the same id as the user except I don't want to get specific in the method I use to persist because I use a form manager as a service and it is common to other actions.</p>
  
  <p>So is it possible to set some annotations to get doctrine to automatically set the student id equal to the user id when creating the student ?
  If yes, how so ?</p>
  
  <p>Thank you a lot,
  Regards</p>