Symfony2 / Doctrine2 - Check Entity Object is new, never persisted
<p>Short and easy question:</p>

<p><strong>How to determine that Doctrine PHP <code>Entity</code> Object is new?</strong></p>

<p><strong>New</strong> - I mean is not in database and its not "update" action.
Most important thing - I need way to check it without any query like:</p>

<pre><code>$manager-&gt;findOne($something);
</code></pre>

<p>Actually sometimes I tried to check "is ID null" but Im not 100% sure this method is valid or not. And other tip or probably core of this question - I seen something like:</p>

<pre><code>$manager-&gt;getUnitOfWork()-&gt;isInIdentityMap($object);
</code></pre>

<p>Looks nice but I can't find what actually do function <code>isInIdentityMap</code>.
Is it true if it was persisted or removed? When this function say true and false?</p>

<hr>

<p><code>//EDIT</code></p>

<p>I need to detect entity object created <strong>first time</strong> - existing only in php but not in database. Of course entity loaded from database to apply updates is not new for me - for example:</p>

<p>When you createing <code>Comment</code> object you need to increment <code>commentCounter</code> but it should be incremented only when you flushing this comment for first time.
You don't want to increment it when you updating or deleting existing comment.
How to check that comment is new and counter should be incremented.</p>

<p><em>Please explain in answers why your method is good/better</em></p>