79243616

Date: 2024-12-02 10:07:46
Score: 1
Natty:
Report link

Can you share more about your application?

If I put the following in an empty Spring Boot application with H2 on the classpath, then everything works as expected:

@Configuration
public class BatchConfiguration {

  private static final Logger LOG = LoggerFactory.getLogger(BatchConfiguration.class);

  @Bean
  Job job(PlatformTransactionManager transactionManager, JobRepository jobRepository) {
    return new JobBuilder("job", jobRepository)
        .start(new StepBuilder("step", jobRepository)
            .<Integer, Integer>chunk(400, transactionManager)
            .reader(reader())
            .writer(writer(null))
            .faultTolerant()
            .skip(Exception.class)
            .skipLimit(1000)
            .listener(new BatchSkipListener())
            .build())
        .build();
  }

  @Bean
  @StepScope
  ListItemReader<Integer> reader() {
    return new ListItemReader<>(List.of(1, 2, 3, 4, 5, 6, 7, 7, 8, 9));
  }

  @Bean
  ItemWriter<Integer> writer(JdbcTemplate jdbcTemplate) {
    return chunk -> jdbcTemplate.batchUpdate(
        "INSERT INTO target_table VALUES (?)",
        chunk.getItems().stream().map(i -> new Object[] {i}).toList(),
        new int[] {Types.BIGINT}
    );
  }

  static class BatchSkipListener implements SkipListener<Integer, Integer> {

    @Override
    public void onSkipInWrite(Integer item, Throwable t) {
      LOG.warn("At {} with {}", item, t.getClass());
    }

  }

}

The content of the schema.sql is:

CREATE TABLE target_table (ID BIGINT PRIMARY KEY);
Reasons:
  • RegEx Blacklisted phrase (2.5): Can you share
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): Can you share
  • High reputation (-1):
Posted by: Henning