Caused by: java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!

Caused by: java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!
at org.hibernate.engine.query.ParameterMetadata.getOrdinalParameterDescriptor(ParameterMetadata.java:55)
at org.hibernate.engine.query.ParameterMetadata.getOrdinalParameterExpectedType(ParameterMetadata.java:61)
at org.hibernate.impl.AbstractQueryImpl.determineType(AbstractQueryImpl.java:397)
at org.hibernate.impl.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:369)
at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:927)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:921)
at com.dtsz.model.base.GenericDaoImpl.query(GenericDaoImpl.java:1252)
at com.dtsz.model.service.jbpm.ReportJBPMRelationManager.getExeceRelationByTaskCodeReportUnit(ReportJBPMRelationManager.java:486)
at com.dtsz.model.service.jbpm.ReportJBPMRelationManager$$FastClassByCGLIB$$3a96e5f7.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
at com.dtsz.model.service.jbpm.ReportJBPMRelationManager$$EnhancerByCGLIB$$49731912.getExeceRelationByTaskCodeReportUnit(<generated>)
at com.dtsz.view.bean.TaskAction.findExecedTask(TaskAction.java:2649)

... 20 more

报这个错的sql语句:

String queryString = " from ReportJBPMRelation R where R.thisTaskCode = ? and R.execedUserIDs like '%?%' and R.status = '0' order by R.thisDate desc";

Object[] params =  new Object[2];
params[0] = taskCode;
params[1] = userID;
reportJBPMRelations = reportJBPMRelationDao.query(queryString, params);


修改后:

String queryString = " from ReportJBPMRelation R where R.thisTaskCode = ? and R.execedUserIDs like '%"+userID+"%' and R.status = '0' order by R.thisDate desc";
reportJBPMRelations = reportJBPMRelationDao.query(queryString, taskCode);


问题发生的原因是:将HQL语句中''中的?没有解析成占位符,确解析成字符串了,又因为是模糊查询,所以只能这样。


你可能感兴趣的:(HQL)