gpt4 book ai didi

java - Hibernate获取SQL query.list() : ArrayIndexOutOfBoundsException 0

转载 作者:行者123 更新时间:2023-11-30 04:23:17 26 4
gpt4 key购买 nike

@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,我使用参数创建它,当我在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

最佳答案

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

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

在这个 native 查询的堆栈跟踪中看到 StandardQueryCache 很奇怪。您是否明确为此查询启用查询缓存?如果是这样,请尝试不使用查询缓存,因为看起来 Hibernate 在派生映射实体的类型以将缓存绑定(bind)到时遇到问题。

关于java - Hibernate获取SQL query.list() : ArrayIndexOutOfBoundsException 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16462036/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com