简体   繁体   中英

Spring Data JPA Query gives java.sql.SQLException: Invalid column type error

Below is my code. I am passing Set as parameter for this query

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

But when I try to run it gives me below error.

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]

I am really stuck at this. Please help

I'm not sure you can pass a collection as the in/out parameter, you can always use spEL in combination with a custom Set that overrides the toString method; something like this:

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

Then the SpecialSet class should override the toString method with this:

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();
}

See SpEL support in Spring Data JPA

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM