title: Error when persisting doctrine entity with OneToMany association
body: <p>New entities in a collection using cascade persist will produce an Exception and rollback the flush() operation. The reason is that the "UserGroupPrivilege" entity has identity through a foreign entity "UserGroup".</p>
  
  <p>But if the "UserGroupPrivilege" has its own identity with auto generated value the code works just fine, and I don't want that I want the identity to be a composite key to enforce validation. here is my code:</p>
  
  <p>Entity UserGroup:</p>
  
  <pre><code>class UserGroup
  {
      /**
       * @var integer
       *
       * @ORM\Column(type="integer", nullable=false)
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="IDENTITY")
       */
      private $id;
  
      /**
       * @var integer
       *
       * @ORM\Column(type="boolean", nullable=false)
       * @Type("integer")
       */
      private $active;
  
  
      /** 
       * @ORM\OneToMany(targetEntity="UserGroupPrivilege", mappedBy="userGroup", cascade={"persist"}) 
       */
      private $privileges;
  </code></pre>
  
  <p>Entity UserGroupPrivilege:</p>
  
  <pre><code>class UserGroupPrivilege
  {    
       /**
       * @var integer
       * 
       * @ORM\Id
       * @ORM\Column(type="integer", nullable=false)
       * 
       */
      private $privilegeId;
  
      /**
       * @var UserGroup
       *
       * @ORM\Id 
       * @ORM\ManyToOne(targetEntity="UserGroup", inversedBy="privileges")
       * @ORM\JoinColumn(name="userGroupId", referencedColumnName="id")
       */
      private $userGroup;  
  
      /**
       * @var string
       * @ORM\Column(type="string", nullable=false)
       */
      private $name;    
  
      /**
       * @var string
       * @ORM\Column(type="string", nullable=false)
       */
      private $value;   
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>$userGroup = new UserGroup();
  $userGroupPrivilege = new UserGroupPrivilege();
  userGroupPrivilege-&gt;setUserGroup($userGroup)
                    -&gt;setName($arrPrivilege['name'])
                    -&gt;setValue($arrPrivilege['value'])
                    -&gt;setPrivilegeId($arrPrivilege['privilegeId']);
  $userGroup-&gt;addPrivilege($userGroupPrivilege);
  $data = $repo-&gt;saveUserGroup($userGroup);
  return $data;
  </code></pre>
  
  <p>Repository:</p>
  
  <pre><code>$em = $this-&gt;getEntityManager();
  $em-&gt;persist($userGroup);
  $em-&gt;flush();
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>Entity of type UserGroupPrivilege has identity through a foreign entity UserGroup, however this entity has no identity itself. You have to call EntityManager#persist() on the related entity and make sure that an identifier was generated before trying to persist 'UserGroupPrivilege'. In case of Post Insert ID Generation (such as MySQL Auto-Increment or PostgreSQL SERIAL) this means you have to call EntityManager#flush() between both persist operations.
  </code></pre>