4
votes

I need to connect with jpa repository from ItemReader using spring batch for Database to text file export. But as of now i tried using JdbcCursorItemReader class to retrieve the data from db. I need to connect with Repository using spring data jpa.

Below is my code used

    @Bean
    public ItemReader<Object> databaseCsvItemReader(@Qualifier("dataSource") DataSource dataSource) throws Exception {
        JdbcCursorItemReader<Object> reader = new JdbcCursorItemReader<Object>();
        reader.setSql(QUERY);
        reader.setDataSource(dataSource);
        reader.setRowMapper(new BeanPropertyRowMapper<>(Object.class));
        return reader;

    }

From this reader i need to connect using Jpa instead of normal jdbc, anyone can help me on this or references it might help me to use jpa.

1

1 Answers

8
votes

I need to connect with Repository using spring data jpa.

RepositoryItemReader is what you are looking for. It allows you to use a Spring Data repository to read items.

You can find examples of how to use it here.