简体   繁体   English

Spring Data JPA查询给出java.sql.SQLException:无效的列类型错误

[英]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 我正在传递Set作为此查询的参数

  @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; 我不确定是否可以将集合作为in / out参数传递,您始终可以将spEL与覆盖toString方法的自定义Set结合使用; 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: 然后,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();
}

See SpEL support in Spring Data JPA 请参阅Spring Data JPA中的SpEL支持

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Data JPA:@Query给出错误java.sql.SQLException:找不到列“ id” - Spring Data JPA: @Query gives error java.sql.SQLException: Column 'id' not found 日期格式错误java.sql.SQLException:列类型无效 - Date Format Error java.sql.SQLException: Invalid column type 通过Java执行SQL查询时,获取错误为“ java.sql.SQLException:无效的列索引” - Getting error as “ java.sql.SQLException: Invalid column index” while executing SQL query through java Spring JDBC和Oracle DB 12c:java.sql.SQLException:无效的列类型。 为什么? - Spring JDBC & Oracle DB 12c: java.sql.SQLException: Invalid column type. Why? java.sql.SQLException:使用 jdbcTemplate 中的 In 子句更新查询的列类型无效 - java.sql.SQLException: Invalid column type for update query with In clause in jdbcTemplate java.sql.SQLException:插入数据时无效的列索引 - java.sql.SQLException: Invalid column index while inserting data java.sql.SQLException:内部错误:无效的类型oid? - java.sql.SQLException: Internal Error: Invalid type oid? java.sql.SQLException: ORA-30081: 下列查询的日期时间/间隔算术的数据类型无效 - java.sql.SQLException: ORA-30081: invalid data type for datetime/interval arithmetic for the below mentioned query java.sql.SQLException:无效的列索引..如何在以下查询中解决此错误? - java.sql.SQLException: Invalid column index .. how can we solve this error in following query? SQL 状态 [null]; 错误代码 [17004]; 列类型无效; 嵌套异常是 java.sql.SQLException: Invalid column type - SQL state [null]; error code [17004]; Invalid column type; nested exception is java.sql.SQLException: Invalid column type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM