2017-01-19 89 views
0

以下是我的代码。我通过设置为此查询参数Spring数据JPA查询给出了java.sql.SQLException:无效的列类型错误

@Query(value = "SELECT * FROM INVOICE_BILL_DATA WHERE INV_BILL_DATA_ID IN :ids ", nativeQuery = true) 
    List<InvoiceBillData> getBillDataForFailedIds(@Param("ids") Set<Long> failedIds); 

但是,当我尝试运行它给了我下面的错误。

Error Code: 17041 
Call: SELECT * FROM INVOICE_BILL_DATA WHERE INV_BILL_DATA_ID IN :ids 
Query: ReadAllQuery(referenceClass=InvoiceBillData sql="SELECT * FROM INVOICE_BILL_DATA WHERE INV_BILL_DATA_ID IN :ids ")] with root cause 

java.sql.SQLException: Missing IN or OUT parameter at index:: 1 
     at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:2076) ~[ojdbc7-12.1.0.2.jar:12.1.0.2.0] 
     at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:4790) ~[ojdbc7-12.1.0.2.jar:12.1.0.2.0] 
     at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:4845) ~[ojdbc7-12.1.0.2.jar:12.1.0.2.0] 
     at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1501) ~[ojdbc7-12.1.0.2.jar:12.1.0.2.0] 
     at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeSelect(DatabaseAccessor.java:1009) ~[org.eclipse.persistence.core-2.6.4.jar:na] 
     at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:644) ~[org.eclipse.persistence.core-2.6.4.jar:na] 
     at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:560) ~[org.eclipse.persistence.core-2.6.4.jar:na] 
     at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2056) ~[org.eclipse.persistence.core-2.6.4.jar:na] 
     at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570) ~[org.eclipse.persistence.core-2.6.4.jar:na] 
     at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242) ~[org.eclipse.persistence.core-2.6.4.jar:na] 
     at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228) ~[org.eclipse.persistence.core-2.6.4.jar:na] 
     at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:299) ~[org.eclipse.persistence.core-2.6.4.jar:na] 
     at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:694) ~[org.eclipse.persistence.core-2.6.4.jar:na] 
     at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:559) ~[org.eclipse.persistence.core-2.6.4.jar:na] 
     at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1175) ~[org.eclipse.persistence.core-2.6.4.jar:na] 
     at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:904) ~[org.eclipse.persistence.core-2.6.4.jar:na] 
     at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1134) ~[org.eclipse.persistence.core-2.6.4.jar:na] 
     at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:460) ~[org.eclipse.persistence.core-2.6.4.jar:na] 
     at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1222) ~[org.eclipse.persistence.core-2.6.4.jar:na] 
     at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896) ~[org.eclipse.persistence.core-2.6.4.jar:na] 
     at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1857) ~[org.eclipse.persistence.core-2.6.4.jar:na] 
     at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1839) ~[org.eclipse.persistence.core-2.6.4.jar:na] 
     at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1804) ~[org.eclipse.persistence.core-2.6.4.jar:na] 
     at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258) ~[org.eclipse.persistence.jpa-2.6.4.jar:na] 
     at org.eclipse.persistence.internal.jpa.QueryImpl.getResultList(QueryImpl.java:473) ~[org.eclipse.persistence.jpa-2.6.4.jar:na] 
     at org.springframework.data.jpa.repository.query.JpaQueryExecution$CollectionExecution.doExecute(JpaQueryExecution.java:118) ~[spring-data-jpa-1.10.3.RELEASE.jar:na] 
     at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:82) ~[spring-data-jpa-1.10.3.RELEASE.jar:na] 
     at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:114) ~[spring-data-jpa-1.10.3.RELEASE.jar:na] 
     at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:104) ~[spring-data-jpa-1.10.3.RELEASE.jar:na] 
     at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:482) ~[spring-data-commons-1.12.3.RELEASE.jar:na] 
     at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460) ~[spring-data-commons-1.12.3.RELEASE.jar:na] 
     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE] 
     at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61) ~[spring-data-commons-1.12.3.RELEASE.jar:na] 
     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE] 
     at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.3.3.RELEASE.jar:4.3.3.RELEASE] 
     at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) ~[spring-tx-4.3.3.RELEASE.jar:4.3.3.RELEASE] 
     at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.3.RELEASE.jar:4.3.3.RELEASE] 
     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE] 
     at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.3.3.RELEASE.jar:4.3.3.RELEASE] 
     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE] 
     at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133) ~[spring-data-jpa-1.10.3.RELEASE.jar:na] 
     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE] 
     at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE] 
     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE] 
     at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE] 
     at com.sun.proxy.$Proxy140.getBillDataForFailedIds(Unknown Source) ~[na:na] 
     at com.oracle.communications.amplify.invoicerepository.service.InvoicingRepoServiceImpl.getInvoiceBillDataToProcess(InvoicingRepoServiceImpl.java:72) ~[main/:na] 
     at com.oracle.communications.amplify.invoicerepository.controller.InvoicingRepoController.getInvoiceBillDataToProcess(InvoicingRepoController.java:81) ~[main/:na] 

我真的被困在这。请帮忙

+0

可以你把你调用这个查询的方法是什么? –

+0

SQL不支持JDBC中的List参数AFAIK –

回答

0

我不确定你可以通过一个集合作为输入/输出参数,你总是可以使用spEL结合自定义Set来覆盖toString方法;是这样的:

@Query("SELECT * FROM INVOICE_BILL_DATA WHERE INV_BILL_DATA_ID IN :#{#ids.toString()}") 
List<InvoiceBillData> getBillDataForFailedIds((@Param("ids") SpecialSet<Long> failedIds); 

然后SpecialSet类应该重写toString方法与此:

public toString(){ 
StringBuilder sb = new StringBuilder(); 
sb.append("("); 
String delim=""; 
for (int i = 0; i < this.size(); i++) { 
     sb.append(delim).append("'").append(this.get(i)).append("'"); 
     delim=","; 
    } 
sb.append(")"); 
return sb.toString(); 
} 

SpEL support in Spring Data JPA

+0

我也尝试使用Query函数,如List findByInvoiceBillDataIdIn(Set failedInvBillDataIds);但是,对于此JPA自动生成的查询会给出错误。 “根本原因”SELECT inv_bill_data_id,account_id,billing_profile_id,CURRENCY,current_total,total_due,due_date,bill_id,previous_total,total_taxes FROM INVOICE_BILL_DATA WHERE(inv_bill_data_id IN(?))“)] java.sql.SQLSyntaxErrorException:ORA-00907:缺少权限括号 JPA添加了额外的括号。 –

+0

看起来像你没有看到我的答案。 –

相关问题