I use database query with JPA like that:
@Query("SELECT " + "new Report(" + "sum (r.fraction1)," + "sum (r.fraction2)) from Report r") Report calculateTotalReports(); 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 CASE WHEN ... THEN, but JPA is not provide it.
Log of crashes:
QueryException: could not instantiate class [com.statistic.server.entity.Report] from tuple] with root cause
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) ~
IFNULLorCOALESCEReport(double, double)try changing it toReport(Double, Double)and maybe you'll be fine.