Search code examples
javapostgresqlspring-webfluxproject-reactorspring-data-r2dbc

ClassCastException: Long cannot be cast to class Integer while saving entity


lately have been getting

java.lang.ClassCastException: class java.lang.Long cannot be cast to class java.lang.Integer (java.lang.Long and java.lang.Integer are in module java.base of loader 'bootstrap')
    at java.base/java.util.stream.Collectors.lambda$summingInt$19(Collectors.java:681)
    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 

while trying to update an entity using r2dbc save method like this:

override suspend fun save(entity: Entity): Entity = r2dbc.save(entity).awaitSingle()

there is no more logic, so I guess classcast exception thrown while trying to parse the updated entity, can't get why this could happen,

I use spring boot version 2.7.9 and org.postgresql:r2dbc-postgresql", version = "1.0.1.RELEASE

My Entity class has id of type Long and in my database table id is bigint

Any help appreciated!


Solution

  • Try to use 0.9.2.RELEASE version of r2dbc driver.

    I was facing the same issue while saving entity with 1.0+ version and spring boot 2.7.*