1
@SuppressWarnings("unchecked")
public List<Object[]> 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 ===============> " + sqlStr);
    List<Object[]> result = new ArrayList<Object[]>();

    return sqlQuery.list();
}

这是一个有点复杂的sql,我使用params创建它,当我在行上运行它时,sqlQuery.list();它给出了这个错误:

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)

但是,当我在查询浏览器中对 sql 查询运行脚本时,它可以正常工作并返回结果。

SQL是:

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
4

1 回答 1

2

我认为您的问题可能与此有关:

https://hibernate.atlassian.net/browse/HHH-6681

StandardQueryCache在您的堆栈跟踪中看到此本机查询的内容很奇怪。您是否为此查询显式启用查询缓存?如果是这样,请尝试不使用查询缓存,因为它看起来像休眠在派生映射实体类型以将缓存绑定到的问题。

于 2013-05-09T13:13:13.937 回答