<p dir="auto"><strong>Symfony version(s) affected</strong>: 3.4.22</p>
<p dir="auto"><strong>Description</strong></p>
<blockquote>
<p dir="auto">A new entity was found through the relationship 'XXX#hcspData' that was not configured to cascade persist operations for entity: HCSPData@0000000023d966fc0000000028e438d7. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example <a class="user-mention notranslate" data-hovercard-type="organization" data-hovercard-url="/orgs/manytoone/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/manytoone">@manytoone</a>(..,cascade={"persist"}). If you cannot find out which entity causes the problem implement 'HCSPData#__toString()' to get a clue.</p>
</blockquote>
<p dir="auto"><strong>How to reproduce</strong><br>
HCSPData is fetched in service, this service is used in Subscriber pinned with Doctrine prePersist.<br>
It was like that since I remember.<br>
Updating Symfony version resulted in above error. Lowering version to .21 and everything works again.<br>
Doctrine package is the same, so I believe this is not Doctrine problem.</p>
<p dir="auto">For <strong>3.4.21</strong><br>
<code class="notranslate">$entityManager-&gt;contains($documentEntity) // true</code><br>
<code class="notranslate">EntityManager { #540 // where HCSPData is fetched</code><br>
<code class="notranslate">EntityManager { #540 // where XXX is flushed</code></p>
<p dir="auto">For <strong>3.4.22</strong><br>
<code class="notranslate">$entityManager-&gt;contains($documentEntity) // false</code><br>
<code class="notranslate">EntityManager { #540 // where HCSPData is fetched</code><br>
<code class="notranslate">EntityManager { #559 // where XXX is flushed</code></p>
<p dir="auto">What i found - <code class="notranslate">EntityManager</code> fetching <code class="notranslate">HCSPData</code> and <code class="notranslate">EntityManager</code> creating new entity in <strong>3.4.21</strong> is the same object, but in <strong>3.4.22</strong> they are not. You had to made change that is breaking DI object injecting. Both service &amp; subscriber are fetching EM same way: <code class="notranslate">public function __construct(EntityManagerInterface $entityManager)</code></p>
<h3 dir="auto"><strong>After some digging I found this:</strong></h3>
<p dir="auto"><a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/symfony/symfony/commit/b3e17d2101530092f96ff9c1967ab2b5f556b90a/hovercard" href="https://github.com/symfony/symfony/commit/b3e17d2101530092f96ff9c1967ab2b5f556b90a"><tt>b3e17d2</tt></a><br>
Reverting changes from this commit done by <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/mmarynich/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/mmarynich">@mmarynich</a> makes everything work again.</p>
<p dir="auto"><strong>Symfony version(s) affected</strong>: 4.2.3</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Updating symfony/dependency-injection (v4.2.2 =&gt; v4.2.3)"><pre class="notranslate"><code class="notranslate">Updating symfony/dependency-injection (v4.2.2 =&gt; v4.2.3)
</code></pre></div>
<p dir="auto">Somehow there are now 2 entity manager instances in my application, causing all sort of WTFs :)</p>
<p dir="auto">See <a href="https://github.com/ro0NL/symfony-issue-30091">https://github.com/ro0NL/symfony-issue-30091</a></p>
<p dir="auto">Before:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="DefaultController.php on line 13:
EntityAwareFactory {#278 ▼
...
  -em: EntityManager {#233 …11}
}
DefaultController.php on line 13:
UserEmailRepository {#212 ▼
...
  -em: EntityManager {#233 …11}
...
}"><pre class="notranslate"><code class="notranslate">DefaultController.php on line 13:
EntityAwareFactory {#278 ▼
...
  -em: EntityManager {#233 …11}
}
DefaultController.php on line 13:
UserEmailRepository {#212 ▼
...
  -em: EntityManager {#233 …11}
...
}
</code></pre></div>
<p dir="auto">Both entity managers are instance 233</p>
<p dir="auto">After</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="DefaultController.php on line 13:
EntityAwareFactory {#278 ▼
...
  -em: EntityManager {#233 …11}
}
DefaultController.php on line 13:
UserEmailRepository {#298 ▼
...
  -em: EntityManager {#283 …11}
...
}"><pre class="notranslate"><code class="notranslate">DefaultController.php on line 13:
EntityAwareFactory {#278 ▼
...
  -em: EntityManager {#233 …11}
}
DefaultController.php on line 13:
UserEmailRepository {#298 ▼
...
  -em: EntityManager {#283 …11}
...
}
</code></pre></div>
<p dir="auto">Now the instances differ. The only differenence is sf/di 4.2.2 vs 4.2.3. Respectively the first and last commit.</p>