title: JPA check if null query
body: <p>I use database query with <code>JPA</code> like that:</p>
  
  <pre><code>@Query("SELECT " +
          "new Report(" +
          "sum (r.fraction1)," +
          "sum (r.fraction2)) from Report r")
  Report calculateTotalReports();
  </code></pre>
  
  <p>When the database is full, it works fine, but when it is empty, the application crashes. How i can check when table contain rows and then select sum? I tried use <code>CASE WHEN ... THEN</code>, but <code>JPA</code> is not provide it.</p>
  
  <p>Log of crashes:</p>
  
  <blockquote>
    <p>QueryException: could not instantiate class
    [com.statistic.server.entity.Report] from tuple] with root cause</p>
    
    <p>java.lang.IllegalArgumentException: null
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    ~[na:1.8.0_201]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    ~[na:1.8.0_201]
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown
    Source) ~</p>
  </blockquote>