JPQL handling null values
<p>Suppose i have the following scenario:</p>

<p>I have an entity <code>Person</code> with attributes  <code>firstName</code> and <code>lastName</code>. Whenever i get a new object <code>Person</code> i want to check whether this person is already in my database. So i check with this <code>@NamedQuery</code>: </p>

<p><code>@NamedQuery(name = "Person.findAlreadyExisting", query = "SELECT p FROM Person p WHERE p.firstname = :firstName and p.lastname = :lastName")</code></p>

<p>But as it turns out, <code>firstName</code> can be <code>null</code> and thus JPQL searches for the String <code>null</code> as the content of the column <code>firstName</code> and of course doesnt find any results.</p>

<p>So my question is, how can I bypass this (unwanted) behaviour, i.e. how do i specify whether i want it to search for the object <code>null</code> or string <code>null</code> without checking every single entry for being <code>null</code>.</p>