I keep getting this error:
- PostGreSQL (16.4) and
- Spring Boot R2DBC (1.0.5.RELEASE) – reactive
relational database connectivity support from Spring Boot
.
java.lang.IllegalArgumentException: Cannot decode value of type long with OID 20
My code:
@Repository
class StudentExtendedRepositoryImpl(
private val databaseClient: DatabaseClient
) : StudentExtendedRepository {
override fun findAllByFirstnameContainingIgnoreCase(firstname: String?): Flow<Student> {
val query = databaseClient
.sql("SELECT * FROM student WHERE firstname ILIKE :firstname")
.bind("firstname", "%$firstname%")
.map { row ->
Student(
row.get("id", Long::class.java),
row.get("firstname", String::class.java) ?: "",
row.get("lastname", String::class.java) ?: "",
row.get("age", Int::class.java) ?: 0
)
}.all()
.asFlow()
return query
}
}
My flyway setup:
CREATE TABLE student(
id BIGSERIAL NOT NULL PRIMARY KEY,
firstname VARCHAR (100),
lastname VARCHAR (20),
age integer
);
Whats going on?
Is there a more sophisticated SQL Query library I can use for Spring R2DBC, instead of having to write custom SQL Querties in the above form?
UPDATE
This fixed it. Not sure why, as I thought java and javaObjectType are the same
Student(
row.get("id", Long::class.javaObjectType),
row.get("firstname", String::class.javaObjectType) ?: "",
row.get("lastname", String::class.javaObjectType) ?: "",
row.get("age", Int::class.javaObjectType) ?: 0
)
4