jboss报错,非常难以解决
13:29:43,250 ERROR [STDERR] java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!
public PurchaseBefore getPurchaseBeforeByMID(int purchaseBeforeID){
try{
Query query = em.createNativeQuery("select n.purchaseApplyID,n.productOrderItemID,n.saleRemarks,n.notPurchaseNum,n.urgent,n.prePurchase,n.createTime,o.billid,m.productname,m.producer,m.specification,m.tprice,m.tcou,(select providername from Provider where providerid=m.providerid) as providername,(select truename from Admin where adminid=o.lastadminid) as truename,b.purchaseBeforeID,b.getNum,b.getPrice,(select providername from Provider where providerid=b.providerid) as providername2,b.purchaseStatus,b.purchaseRemarks,b.confirmPurchase,b.createTime,b.total from PurchaseApply n left join ProductOrderItem m on n.productOrderItemID=m.productorderitemid left join Productorder o on m.orderid=o.orderid left join purchaseBefore b on b.purchaseApplyID=n.purchaseApplyID order by n.purchaseApplyID desc");
query.setParameter(1,purchaseBeforeID);
List list=query.getResultList();
if(list.size()==1){
PurchaseBefore hfAD=(PurchaseBefore)list.get(0);
return hfAD;
}else{
return null;
}
}catch (Exception e) {
e.printStackTrace();
return null;
}
}
[解决办法]
请问我的问题出现在哪里?谢谢各位大侠的指点
[解决办法]
if(list.size()==1){
这个判断可能有问题
改为
if(list!=null && list.size()>=0){
[解决办法]
另外,这个参数purchaseBeforeID 传给那个变量了
[解决办法]
IndexOutOfBoundsException
超过长度了
[解决办法]
如果你的list为空的话,用list.size()就会有问题的,不过这个不关jboss的事
[解决办法]
错在:
query.setParameter(1,purchaseBeforeID);
[解决办法]
query.setParameter(1,purchaseBeforeID);有问题,
前面的sql查询没有需要设置参数/变量的地方。要修改前面的sql语句
[解决办法]
1. log 报的是query.setParameter(1,purchaseBeforeID);这一句,sql没有set参的地方。
2. list 需要先check null
[解决办法]
建议调试运行,确定抛出异常的那条语句
[解决办法]
9楼说得对,sql语句中没有需要传参的地方
[解决办法]
数组 越界 问题。
[解决办法]
null