0

In spring data jdbc bundled with spring boot 3.0.5 I could generate an Id by using the BeforeConvertCallback:

@Configuration
@EnableJdbcRepositories
class JdbcConfig extends AbstractJdbcConfiguration {

    @Bean
    BeforeConvertCallback<MyEntity> beforeSaveCallback() {
        return (entity) -> {
            if (entity.getId() == null) {
                entity.setId(UUID.randomUUID().toString());
            }
            return entity;
        };
    }

With 3.0.6 I get now an SQL error ('ERROR: null value in column "id" of relation'), that the Id is missing, therefore I assume that the BeforeConvertCallback is not longer called.

I went through all versions >= 3.0.6 and none of them have the behaviour I expect.

  • That sounds like a regression. Could you please create a ticket on Github, with a reproducer? – Jens Schauder Jun 12 '23 at 13:51
  • Yes, I will do. – hubert.volz Jun 12 '23 at 17:16
  • The repo to reproduce is here: https://github.com/hubertvolz/becoca. – hubert.volz Jun 12 '23 at 18:05
  • And now a github issue is also created: https://github.com/spring-projects/spring-data-relational/issues/1532. @JensSchauder: if something is missing or unclear, don't hesitate to ask me. I don't have experience in creating meaningful github issues and proper code to reproduce problems. – hubert.volz Jun 12 '23 at 18:15

1 Answers1

0

As Mark Paluch commented on the related Github issue the problem is a regression that causes lambdas not to get picked up as callbacks.

He recommends the following workarounds

Please avoid lambdas

or

Another workaround is moving the lambda callbacks into a non-@Configuration class that you import via @Import(…).

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348