oracle / oracle-r2dbc

R2DBC Driver for Oracle Database
https://oracle.com
Other
197 stars 40 forks source link

Unsupported Java type:class java.util.ArrayList exception when using IN clause in sql #116

Closed lhmlyz closed 1 year ago

lhmlyz commented 1 year ago

Hello, I use oracle-r2dbc (v1.1.0) in my spring boot application without spring-data-r2dbc and r2dbc-pool. I receive Unsupported java type:class java.util.ArrayList exception when I send List type data to my query.

Sample query: SELECT c.name AS "firstName", c.lastname AS "lastName" FROM customer c, WHERE c.id IN (:ids)

Java Code:

private Mono<List<Customer>> findByParam(Connection connection, String query, String name, Object param) {
return Flux.from(connection.createStatement(query)
                .bind(name, param)
                .execute())
        .concatMap((Function<Result, Publisher<Customer>>) result -> result.map(rowMapper()))
        .collectList()
        .cache();
}

public Mono<List<Customer>> findCustomerById(List<Integer> customerIds) {
return Mono.usingWhen(connection.create(),
        con -> findByParam(con, query, "ids", customerIds), Connection::close);
}
Michael-A-McMahon commented 1 year ago

Unfortunately, Oracle Database does not support the IN (:ids) syntax. To accomplish a bind of a list, we need to generate an IN clause having a parameter marker for each value in the list. I wrote an example of that here: https://github.com/oracle/oracle-r2dbc/issues/56

I hope this helps.