title: Spring data jpa. Find max if no result return default value
body: <p>I've implemented in my spring repository interface:</p>
  
  <pre><code>@Query("SELECT max(ch.id) FROM MyEntity ch")
  Long getMaxId();
  </code></pre>
  
  <p>It works correctly if db is not empty. If I start my environment with test configuration (H2DB is used) - there is no data in the very beginning. And result returned by <code>getMaxId()</code> is <strong>null</strong>. I would like to have here <strong>0</strong>.</p>
  
  <hr>
  
  <p>Is it possible to modify my <code>*JpaRepository</code> to have <strong>0</strong> result? If yes, how it should be modified?</p>