我试图在下面的查询中传递List as Parameter然后调用Hibernate Bulk update,在调用我得到以下异常时,请让我知道如何将list设置为条件中的param值。 查询如下---- 插入存档(cust_id,orderNum,country,extractionType,errorCode,extractionDate)" + "从OrderTest中选择cust_id,orderNum,country,extractionType,errorCode,extractionDate,其中cust_id =:ids
我的java代码是
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
Session session = sessionFactory.getCurrentSession();
List<OrderTest> customerIdList = getPurgeCriteria(session);
if (null != customerIdList) {
StringBuffer cust_ids = new StringBuffer();
String purgeStatement = "insert into OrderArchive(cust_id, orderNum, country, extractionType, errorCode, extractionDate)"
+ " select * from OrderTest where cust_id in (:ids)";
// Criteria purgeCriteria =
// Criteria.createCriteria(OrderTest.class,purgeStatement);
Query purgeQuery = session.createQuery(purgeStatement);
// purgeQuery.setParameterList("ids", customerIdList);
/*
* for(String cust_id : customerIdList) {
* cust_ids.append(cust_id).append(","); purgeCriteria.setParameter("ids",
* cust_ids.toString()); System.out.println(cust_id); }
*/
// purgeCriteria.setParameter("ids", customerIdList);
// purgeCriteria.setParameter("ids", customerIdList);
String deleteStatement = "delete from OrderTest where cust_id in (:delIds)";
// Criteria deleteCriteria =
// Criteria.createCriteria(OrderTest.class,deleteStatement);
// deleteCriteria.setParameter("delIds", customerIdList);
Query deleteQuery = session.createQuery(deleteStatement);
deleteQuery.setParameterList("delIds", customerIdList);
try {
int res = purgeQuery.executeUpdate();
// int res = purgePersistenceManager.update(purgeCriteria);
logger.info("No of records inserted into archive table :" + res);
if (res > 0) {
int rows = deleteQuery.executeUpdate();
// int rows = purgePersistenceManager.update(deleteCriteria);
logger.info("No of records deleted from order test table :" + rows);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
java.lang.IndexOutOfBoundsException:记住序数参数 是1基于! 在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:382) 在org.hibernate.impl.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:362) 在org.springframework.orm.hibernate3.HibernateTemplate $ 39.doInHibernate(HibernateTemplate.java:1147) 在org.springframework.orm.hibernate3.HibernateTemplate $ 39.doInHibernate(HibernateTemplate.java:1141) 在org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406) 在org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374) 在org.springframework.orm.hibernate3.HibernateTemplate.bulkUpdate(HibernateTemplate.java:1141) 在in.gov.uidai.platform.impl.persistence.handler.HibernateHandler.update(HibernateHandler.java:312) 在in.gov.uidai.platform.impl.persistence.provider.AbstractPersistenceProvider.update(AbstractPersistenceProvider.java:110) 在in.gov.uidai.platform.impl.persistence.PersistenceDelegate.update(PersistenceDelegate.java:152) 在in.gov.uidai.platform.impl.persistence.PersistenceDelegate $$ FastClassByCGLIB $$ 9f7b2e03.invoke() 在org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) 在org.springframework.aop.framework.CglibAopProxy $ CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698) 在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) 在org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106) 在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 在org.springframework.aop.framework.CglibAopProxy $ DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631) 在in.gov.uidai.platform.impl.persistence.PersistenceDelegate $$ EnhancerByCGLIB $$ e4e1748.update() 在in.gov.uidai.platform.impl.persistence.PersistenceManagerProvider.update(PersistenceManagerProvider.java:320) 在in.gov.uidai.platform.impl.persistence.PersistenceManagerProvider.update(PersistenceManagerProvider.java:277) at batch.impl.tasklets.PurgeProcessor.execute(PurgeProcessor.java:88) 在org.springframework.batch.core.step.tasklet.TaskletStep $ ChunkTransactionCallback.doInTransaction(TaskletStep.java:406) 在org.springframework.batch.core.step.tasklet.TaskletStep $ ChunkTransactionCallback.doInTransaction(TaskletStep.java:330) 在org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:128) 在org.springframework.batch.core.step.tasklet.TaskletStep $ 2.doInChunkContext(TaskletStep.java:271) 在org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:77) 在org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:368) 在org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) 在org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144) 在org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257) 在org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:198) 在org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) 在org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64) 在org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67) 在org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:162) 在org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:141) 在org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134) 在org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:304) 在org.springframework.batch.core.launch.support.SimpleJobLauncher $ 1.run(SimpleJobLauncher.java:135) 在org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49) 在org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128) at batch.impl.jobs.BatchJob.execute(BatchJob.java:48) 在org.quartz.core.JobRunShell.run(JobRunShell.java:199) 在org.quartz.simpl.SimpleThreadPool $ WorkerThread.run(SimpleThreadPool.java:549
答案 0 :(得分:0)
尝试单独执行此查询,因为认为此查询提供multirow:
" select * from OrderTest where cust_id in (:ids)";
为此,它会给出错误
答案 1 :(得分:0)
首先执行purgeStatement,然后应用选择查询。 如果要更新数据,请使用保存或更新并在该
中使用where子句字符串purgeStatement =“插入OrderArchive(cust_id,orderNum,国家/地区,提取类型,错误代码,提取日期)”;
String selectStatement =“ select * from OrderArchive,其中cust_id位于(:ids)中”;