org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of java.util.ArrayList.
Use setObject() with an explicit Types value to specify the type to use.
μνλ μμ
κ°κ° κ²μνμ μ Queryμ κ°―μκ° λ무 λ§μμ§λ κ²μ μ°λ €ν΄ listμμ idκ° μλ κ²½μ° κ°μ Έμ€λ SQLμ μ§λ €κ³ νλ€.
select * from public.game_id_name where app_id in (?)
μ€λ₯ λ°μ μ½λ
νμ§λ§ μμ μλ¬κ° λ°μνκ³ postgresqlμ κ²½μ° java list νμ μΌλ‘ μ‘°νν μ μλ€λ κ²μ μκ² λμλ€.
public List<GameInfo> gamesDetailInfoFindById(List<Long> idList) {
String sql = "select * from public.game_id_name where app_id in (?)";
try {
return jdbcTemplate.query(refinedSQL, gameRowMapper(), idList);
} catch (IncorrectResultSizeDataAccessException e) {
throw new CommonException(ResponseCode.INVALID_GAME_ID);
}
}
ν΄κ²° μ½λ
μ¬λ¬ λ°©μμΌλ‘ μλνμΌλ μ΄ν΄ κ°λ₯ν μ μμ κ°μ₯ κ°νΈν λ°©μμ "(1, 2, 3)" μ΄λ° κΌ΄λ‘ stringμ λ§λ€μ΄ λ체νλ λ°©μμ΄μλ€.
public List<GameInfo> gamesDetailInfoFindById(ArrayList<Long> idList) {
String sql = "select * from public.game_id_name where app_id in (:ids)";
String idListString = "";
int i=0;
for (Long id: idList){
if (i < idList.size()-1){
idListString = idListString + id + ",";
}
else {
idListString = idListString + id;
}
i++;
}
String refinedSQL = sql.replace(":ids",idListString);
try {
return jdbcTemplate.query(refinedSQL, gameRowMapper());
} catch (IncorrectResultSizeDataAccessException e) {
throw new CommonException(ResponseCode.INVALID_GAME_ID);
}
}
μ array νμμ΄ μ§μμ΄ μλλ κ²μΈμ§ μμνλ€..
ormμ΄ λ§μ΄ μ°μ΄λ€λ³΄λ κ·Έλ°μ§
κ½€ μμ£Ό λ°μν μ μλ μ€λ₯μμλ ꡬκΈλ§μ λ§μ μλ£κ° λμ€μ§ μμ ν¬μ€ν ν΄λ³Έλ€!
λ°μν
'κ°λ° > Spring' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
Spring batch - JobInstanceAlreadyCompleteException ν΄κ²° (0) | 2024.01.14 |
---|---|
domain, entity, dao, dto, vo ?? (0) | 2022.05.06 |
μ€νλ§ μΉ κ°λ° λ°©μ (static / MVC / API) (0) | 2022.03.03 |
Spring νλ‘μ νΈ μμ± (Gradle) (0) | 2022.03.03 |
ZonedDateTime (UTC -> KST) (0) | 2022.02.23 |