Skip to content

Improve R2dbcCustomConversions creation when using a dialect to ensure registration of driver-simple types #628

@anuger

Description

@anuger

springboot version: 2.4.7
spring-data-r2dbc version: 1.2.9

entity:

public class MessageBody {
    private String msg:
}
public class Message {
    private Integer id;
    private MessageBody body;
}

Repository

public interface MessageRepository extends R2dbcRepository<Message, Integer> {
}

when i call MessageRepository.save(), i get the exception:

reactor.core.Exceptions$ErrorCallbackNotImplemented: org.springframework.dao.InvalidDataAccessApiUsageException: Nested entities are not supported
Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Nested entities are not supported

If change Message.body to String:

public class Message {
    private Integer id;
    private String body;
}

get exception:

reactor.core.Exceptions$ErrorCallbackNotImplemented: org.springframework.r2dbc.BadSqlGrammarException: executeMany; bad SQL grammar [INSERT INTO message (body) VALUES ($1)]; nested exception is io.r2dbc.postgresql.ExceptionFactory$PostgresqlBadGrammarException: [42804] column "body" is of type json but expression is of type character varying
Caused by: org.springframework.r2dbc.BadSqlGrammarException: executeMany; bad SQL grammar [INSERT INTO message (body) VALUES ($1)]; nested exception is io.r2dbc.postgresql.ExceptionFactory$PostgresqlBadGrammarException: [42804] column "body" is of type json but expression is of type character varying

after add @WritingConverter:

public class MessageBodyWriteConverter implements Converter<MessageBody, Json> {
    @Override
    public Json convert(MessageBody messageBody) {
        return Json.of(new ObjectMapper().writeValueAsString(messageBody));
    }
}

get exception:

reactor.core.Exceptions$ErrorCallbackNotImplemented: org.springframework.dao.DataIntegrityViolationException: executeMany; SQL [INSERT INTO message (body) VALUES ($1)]; null value in column "body" violates not-null constraint; nested exception is io.r2dbc.postgresql.ExceptionFactory$PostgresqlDataIntegrityViolationException: [23502] null value in column "body" violates not-null constraint
Caused by: org.springframework.dao.DataIntegrityViolationException: executeMany; SQL [INSERT INTO message (body) VALUES ($1)]; null value in column "body" violates not-null constraint; nested exception is io.r2dbc.postgresql.ExceptionFactory$PostgresqlDataIntegrityViolationException: [23502] null value in column "body" violates not-null constraint

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions