title: Spring Data JPA could not instantiate class
body: <p>I have problem with my code. </p>
  
  <p>I paste below my DAO interface:</p>
  
  <pre><code>public interface EventDao extends CrudRepository&lt;Event, Integer&gt;{
  ...
  @Query("SELECT new com.patryk.entity.ActionStatistics(e.action.actionname,sum(e.lengthinmilis)) FROM Event e where e.user = ?1 and e.removed = 0 and year(e.createdate) = year(?2) and month(e.createdate)=month(?2) and e.action.isworkingaction = 1")
  public List&lt;ActionStatistics&gt; findMonthlyUserStatisticsByUserAndCreateDay(User user, Date createday);
  ...
  }
  </code></pre>
  
  <p>ActionStatistics Class:</p>
  
  <pre><code>        package com.patryk.entity;
  
          import java.text.SimpleDateFormat;
          import java.util.Date;
          import java.util.TimeZone;
  
          public class ActionStatistics {
  
              private String actionname;
              private long time;
              private String timeString;
  
              public ActionStatistics() {
                  this.actionname = "actionname";
                  this.time = 0;
              }
  
              public ActionStatistics(String actionname, long time) {
                  this.actionname = actionname;
                  this.time = time;
              }
  
              public String getActionname() {
                  return actionname;
              }
  
              public void setActionname(String actionname) {
                  this.actionname = actionname;
              }
  
              public long getTime() {
                  return time;
              }
  
              public void setTime(long time) {
                  this.time = time;
              }
  
              public String getTimeString() {
                  SimpleDateFormat sdt = new SimpleDateFormat("HH:mm:ss");
                  sdt.setTimeZone(TimeZone.getTimeZone("UTC"));
                  return sdt.format(new Date(getTime()));
              }
  
              public void setTimeString(String timeString) {
                  this.timeString = timeString;
              }
  
              @Override
              public String toString() {
                  return "ActionStatistics{" + "actionname=" + actionname + ", time=" + time + ", timeString=" + timeString + '}';
              }
          }
  </code></pre>
  
  <p>I get error like this, my stacktrace:</p>
  
  <pre><code>2016-12-04 15:49:45.218 ERROR 7224 --- [nio-8084-exec-6] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.QueryException: could not instantiate class [com.patryk.entity.ActionStatistics] from tuple; nested exception is java.lang.IllegalArgumentException: org.hibernate.QueryException: could not instantiate class [com.patryk.entity.ActionStatistics] from tuple] with root cause
  
  java.lang.IllegalArgumentException: null
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_111]
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_111]
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_111]
  at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_111]
  ...
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_111]
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_111]
  at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.4.jar:8.5.4]
  at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]
  </code></pre>
  
  <p>Query which throw exception:</p>
  
  <pre><code>mysql&gt; select action1_.actionName as col_0_0_, sum(event0_.lengthInSec) as col_1_0_ from Events event0_, Actions action1_ where event0_.actionID=action1_.actionID and event0_.userID=2 and event0_.removed=0 and year(event0_.createDate)=year(now()) and month(event0_.createDate)=month(now()) and action1_.isWorkingAction=1;
  +----------+----------+
  | col_0_0_ | col_1_0_ |
  +----------+----------+
  | NULL     |     NULL |
  +----------+----------+
  1 row in set (0.00 sec)
  mysql&gt; 
  </code></pre>
  
  <p>Where am I doing something wrong ? How I can solve it ?</p>