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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With