title: Is there a way to check for null ZonedDateTime in JPQL?
body: <p>In some E2E tests I'm faced with a problem. Let's say, I have the following JPQL query:</p>
  
  <pre><code>Query query = entityManager.createQuery(
          " select d from Document d left join d.audit da " +
          " where " +
          " (cast(:startDate as java.time.ZonedDateTime)) is null " +
          "    or truncate_for_minutes(da.dateCreate, 'UTC') &gt;= " +
          " truncate_for_minutes(:startDate, 'UTC')")
          .setParameter("startDate", ZonedDateTime.now());
  </code></pre>
  
  <p>In the query string I use named parameter <code>startDate</code> which can be <code>null</code>. The query above works. But if I pass <code>null</code>, the following exception is thrown:</p>
  
  <pre><code>Caused by: org.postgresql.util.PSQLException: 
  ERROR: cannot cast type bytea to timestamp without time zone
  </code></pre>
  
  <p>Without type casting the following exception is thrown:</p>
  
  <pre><code>Caused by: org.postgresql.util.PSQLException: 
  ERROR: could not determine data type of parameter $1
  </code></pre>
  
  <p>Without check for null the following exception is thrown:</p>
  
  <pre><code>Caused by: org.postgresql.util.PSQLException: 
  ERROR: function pg_catalog.timezone(unknown, bytea) does not exist
  No function matches the given name and argument types. 
  You might need to add explicit type casts.
  </code></pre>
  
  <p>I use this query in Spring Data repository by using <code>@Query</code> string. Function <code>truncate_for_minute(...)</code> - is just a small customization for the PostgreSQL function <code>date_trunc(...)</code>.</p>
  
  <p>I know that I can implement custom repository and build query string dynamically, but why I can't check for <code>null</code> <code>ZonedDateTime</code> in JPQL string? Maybe there is a way to do it?</p>
  
  <p>My environment:</p>
  
  <ul>
  <li>Java 11</li>
  <li>PostgreSQL 11.3 on x86_64-pc-linux-musl, compiled by gcc (Alpine 8.3.0) 8.3.0, 64-bit</li>
  <li>Hibernate 5.3.7 Final</li>
  </ul>