Reputation: 1164
Spring Boot version: 2.1.2.RELEASE
H2 version: 1.4.197
Query over JpaRepository:
@Repository
public interface PlayerStorage extends JpaRepository<Player, Long> {
List<Player> findByUid(@Param("uid") List<Integer> uid);
}
...
List<Player> foundByUids = playerStorage.findByUid(Arrays.asList(100, 200));
Spring generates and executes a query:
Data conversion error converting "(100, 200)"; SQL statement:
select
player0_.id as id1_3_,
player0_.uid as uid3_3_
from
player player0_
where
player0_.uid=(100 , 200)
[22018-197]
...
Caused by: java.lang.NumberFormatException: For input string: "(100, 200)"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:569)
at java.lang.Integer.parseInt(Integer.java:615)
at org.h2.value.Value.convertTo(Value.java:1061)
H2 says:
DATA_CONVERSION_ERROR_1 = 22018
The error with code 22018 is thrown when trying to convert a value to a data type where the conversion is undefined, or when an error occurred trying to convert.
Example:
CALL CAST(DATE '2001-01-01' AS BOOLEAN);
CALL CAST('CHF 99.95' AS INT);
I get the same result if I try to execute this query directly from the H2 web console. If I got it right, the problem is in the statement: player0_.uid=(100 , 200)
. The same query with the in player0_.uid in (100 , 200)
executes fine from the web console.
Also I have the spring boot properties for H2:
spring.datasource.driver-class-name=org.h2.Driver
spring.jpa.database=H2
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
Upvotes: 0
Views: 1180
Reputation: 4365
Probably, the error is in repository code:
public interface PlayerStorage extends JpaRepository<Player, Long> {
List<Player> findByUid(@Param("uid") List<Integer> uid);
}
From documentation it should be:
public interface PlayerStorage extends JpaRepository<Player, Long> {
List<Player> findByUidIn(@Param("uid") List<Integer> uid);
}
Also:
Upvotes: 3
Reputation: 2506
Try to rename your method to
List<Player> findByUidIn(@Param("uids") List<Integer> uids);
Upvotes: 2