Doctrine inserts twice when adding one related entity and using $em->clear()
<p>When I try to add new info item it either inserts two of them or none. In the state of code below it inserts two. If i comment something it inserts none. When I comment the line with $em->clear() it inserts exactly one, as I need it. What I don't understand and what I'm  doing wrong?</p>

<pre><code>$limit = 10;
$offset = 0;
do {
    $products = $selectedModelQuery-&gt;getQuery()
        -&gt;setFirstResult($limit * $offset)
        -&gt;setMaxResults($limit)-&gt;getResult();
    $offset++;
    $count = count($products);
    /** @var \Nti\ApiBundle\Entity\Product $product */
    foreach ($selectedModelQuery-&gt;getQuery()-&gt;getResult() as $product) {
        if (!$product-&gt;getCollections()-&gt;contains($productCollection)) {
            $product-&gt;addCollection($productCollection);

            $productInfo = new ProductInfo;
            $productInfo-&gt;setProduct($product);
            $productInfo-&gt;setData($productCollection-&gt;getMessage());
            $productInfo-&gt;setInfoType(ProductInfoInterface::TYPE_CUSTOM);

            //$em-&gt;merge($product);
            //$em-&gt;persist($productInfo);
        }
    }
    $em-&gt;flush();
    $em-&gt;clear();
} while ($count);
</code></pre>

<p>Main Entity:</p>

<pre><code>class Product {
    /**
     * @ORM\OneToMany(targetEntity="ProductInfo", mappedBy="product", cascade={"persist", "remove"})
     * @var ProductInfoInterface[]|ArrayCollection
     */
    protected $infoList;
    ....
}
</code></pre>

<p>Related Entity:</p>

<pre><code>class ProductInfo {
    /**
     * @ORM\ManyToOne(targetEntity="\Nti\ApiBundle\Entity\Product", inversedBy="infoList")
     * @ORM\JoinColumn(name="product_id", referencedColumnName="id", onDelete="CASCADE", nullable=false)
     */
    protected $product;
    ...
}
</code></pre>