2017-01-19 16 views
0

以下は私のコードです。私はこのクエリのパラメータとしてSetを渡しています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

あなたはin/outパラメータとしてコレクションを渡すことができませんが、toStringメソッドをオーバーライドするカスタムセットと組み合わせて常にspELを使用できます。このような何か:

@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

List findByInvoiceBillDataIdIn(failedInvBillDataIds)のようなクエリ機能を使用しようとしました。しかし、このJPA自動生成クエリでは、エラーが発生します。 ORA-00907:根が原因ので、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)括弧 JPAは余分な括弧を追加します。 –

+0

私の答えを読まなかったようです。 –

関連する問題