Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect JPARepository with ItemReader using spring batch?

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.

like image 251
Manoj Kumar Avatar asked Jan 26 '23 07:01

Manoj Kumar


1 Answers

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.

like image 190
Mahmoud Ben Hassine Avatar answered Jan 30 '23 00:01

Mahmoud Ben Hassine