When I try to insert an entity with only an id using spring r2dbc data I got the following exception:
Exception while fetching data (addChat) : INSERT contains no values
java.lang.IllegalStateException: INSERT contains no values
at org.springframework.data.r2dbc.core.DefaultStatementMapper.getMappedObject(DefaultStatementMapper.java:159) ~[spring-data-r2dbc-1.0.0.RC1.jar:1.0.0.RC1]
at org.springframework.data.r2dbc.core.DefaultStatementMapper.getMappedObject(DefaultStatementMapper.java:144) ~[spring-data-r2dbc-1.0.0.RC1.jar:1.0.0.RC1]
Database postgres:
create table chats
(
id serial not null
constraint chats_pkey
primary key
);
Entity
import org.springframework.data.annotation.Id
import org.springframework.data.relational.core.mapping.Table
@Table("chats")
data class ChatEntity(
@Id val id: Int? = null
)
Repository:
import org.springframework.data.r2dbc.repository.R2dbcRepository
import org.springframework.stereotype.Repository
@Repository
interface ChatsRepository : R2dbcRepository<ChatEntity, Int>
Service:
//Service
val chatAdded = chatsRepository.save(ChatEntity(id = null)).awaitFirst()
On the same project I have other entities with id and other columns that works fine. Any idea why I have this error?