How to connect JPARepository with ItemReader using spring batch?
Asked Answered
S

1

5

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.

Sweetscented answered 16/5, 2019 at 7:43 Comment(0)
I
10

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.

Immiscible answered 16/5, 2019 at 8:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.