title: Hibernate get SQL query.list() : ArrayIndexOutOfBoundsException 0
body: <pre><code>@SuppressWarnings("unchecked")
  public List&lt;Object[]&gt; findAdcampStatistics(Long adcampId, String startDate, String endDate, float costPerClick, String orderStatus){
      String sqlStr = 
              "SELECT adcamp_id, alternative_ids, click, orderCount, conversion, ((100*orderCount)/click) AS conversionRate, (click * " + (costPerClick != 0?costPerClick:0) + ") AS cost " +
              "FROM ( " +
                  "SELECT adcamp_id, alternative_ids, COUNT(*) AS click, " +
                      "SUM(( " + 
                          "SELECT COUNT(*) "+
                          "FROM nc_order, nc_cart "+
                          "WHERE nc_order.cart_id = nc_cart.id "+
                              "AND nc_cart.adcamp_click_id = nc_adcamp_click.id "+
                              (orderStatus != ""? "AND nc_order.order_status = '"+ orderStatus +"' " : " ")+
                          " )) AS orderCount, "+
                      "SUM(( " + 
                          "SELECT SUM(nc_payment_log.amount) "+
                          "FROM nc_order, nc_cart, nc_payment_log "+
                          "WHERE nc_order.payment_log_id = nc_payment_log.id "+
                              "AND nc_order.cart_id = nc_cart.id "+
                              "AND nc_cart.adcamp_click_id = nc_adcamp_click.id " +  
                              (orderStatus != ""? "AND nc_order.order_status = '"+ orderStatus +"' " : " ") +
                          " )) AS conversion "+
                  "FROM nc_adcamp_click "+
                  "WHERE "+ 
                      (adcampId!=0? "adcamp_id =" + adcampId.toString() + " AND ":" ") +
                      "date_clicked BETWEEN '" + startDate + "' AND '" + endDate + "' "+
                  "GROUP BY alternative_ids "+
              ") AS temp";
  
      SQLQuery sqlQuery = getSQLQuery(sqlStr);
      System.out.println("ADCAMP SQL ===============&gt; " + sqlStr);
      List&lt;Object[]&gt; result = new ArrayList&lt;Object[]&gt;();
  
      return sqlQuery.list();
  }
  </code></pre>
  
  <p>Here is a little complicated sql, I am creating it by using params, and when I run it on the line <code>sqlQuery.list();</code> it gives this error: </p>
  
  <pre><code>java.lang.ArrayIndexOutOfBoundsException: 0
  at org.hibernate.type.TypeHelper.disassemble(TypeHelper.java:146)
  at org.hibernate.cache.StandardQueryCache.put(StandardQueryCache.java:106)
  at org.hibernate.loader.Loader.putResultInQueryCache(Loader.java:2443)
  at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2321)
  at org.hibernate.loader.Loader.list(Loader.java:2268)
  at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:316)
  at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1842)
  at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:165)
  at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:157)
  at com.netasoft.commerce.framework.marketing.dao.AdCampDaoImpl.findAdcampStatistics(AdCampDaoImpl.java:71)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
  at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
  at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
  at $Proxy96.findAdcampStatistics(Unknown Source)
  at com.netasoft.commerce.framework.marketing.service.MarketingServiceImpl.findAdcampStatistics(MarketingServiceImpl.java:71)
  at com.netasoft.commerce.framework.adminint.controller.ReportController.adcamp(ReportController.java:55)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)
  at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
  at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
  at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
  at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
  </code></pre>
  
  <p>however when I run script on sql query in Query Browser it works without exception and return results.</p>
  
  <p>SQL is:</p>
  
  <pre><code>SELECT adcamp_id, alternative_ids, click, orderCount, conversion, (100*orderCount)/click AS conversionRate, (click * 1.0) AS cost 
  FROM ( SELECT adcamp_id, alternative_ids, COUNT(*) AS click, 
     SUM(( SELECT COUNT(*) FROM nc_order, nc_cart WHERE nc_order.cart_id = nc_cart.id AND nc_cart.adcamp_click_id = nc_adcamp_click.id AND nc_order.order_status = 'delivered'  )) AS orderCount, 
     SUM(( SELECT SUM(nc_payment_log.amount) FROM nc_order, nc_cart, nc_payment_log WHERE nc_order.payment_log_id = nc_payment_log.id AND nc_order.cart_id = nc_cart.id AND nc_cart.adcamp_click_id = nc_adcamp_click.id AND nc_order.order_status = 'delivered'  )) AS conversion 
     FROM nc_adcamp_click 
     WHERE adcamp_id =1 AND date_clicked BETWEEN '2013-02-09' AND '2013-05-09' 
     GROUP BY alternative_ids 
  ) AS temp
  </code></pre>