JPA将列表传递到本机查询中的IN子句

ddrv8njm  于 12个月前  发布在  Spring
关注(0)|答案(2)|浏览(225)

我有这样的疑问:

@Query(
      value = "select distinct ID_RIGHT from TDK_SEC_HOTEL_RIGHT osrr where osrr.ID_RIGHT in ?1", 
      nativeQuery = true)
        List<String> findAllByHOTELs(List<String> HOTELs);

字符串
但是我在运行时遇到了这个错误:

Caused by: java.sql.SQLException: Invalid column type
at oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:8547)
at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:8029)
at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:8804)
at oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement.java:8779)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.setObject(OraclePreparedStatementWrapper.java:217)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native
Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.tomcat.jdbc.pool.StatementFacade$StatementProxy.invoke(StatementFacade.java:118)
at com.sun.proxy.$Proxy143.setObject(Unknown Source)
at org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.setParameterValueInDatabaseCall(DatabasePlatform.java:2648)
at org.eclipse.persistence.internal.databaseaccess.DatabaseCall.prepareStatement(DatabaseCall.java:836)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:628)
... 100 more
11:01:36.510 [https-openssl-apr-1062-exec-1] ERROR
com.hostels.web.filter.HostelsResponseFilter - Request
processing failed; nested exception is
org.springframework.orm.jpa.JpaSystemException: Exception
[EclipseLink-4002] (Eclipse Persistence Services -
2.7.5.v20191016-ea124dd158):
org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Invalid column type
Error Code: 17004
Call: select distinct ID_RIGHT from TDK_SEC_HOTEL_RIGHT osrr where
osrr.ID_RIGHT in ?

brtdzjyr

brtdzjyr1#

你可以试试这个查询:

@Query(
      value = "select distinct ID_RIGHT from TDK_SEC_HOTEL_RIGHT osrr where osrr.ID_RIGHT in :hotels", 
      nativeQuery = true)
List<String> findAllByHOTELs(@Param("hotels") List<String> HOTELs);

字符串
在上面的查询中,:hotels是绑定到HOTEL列表的命名参数。

5fjcxozz

5fjcxozz2#

您需要分享更多的信息来调试错误。
根据错误Invalid column type,我怀疑ID_RIGHT的变量类型有问题。根据您提供的代码,此列的类型应该是VARCHAR(因为它Map到String)。

相关问题