Reputation: 86727
I want to use spring-batch
for retrieving and processing data from a postgres db.
I have a working SQL statement that would give me the full result set (about 400k entries):
private static final String QUERY = "SELECT * FROM MyDataTable ";
Now I want to use the JpaPagingItemReader
so that the data is fetched (and written elsewhere) in chunks:
JpaPagingItemReader<MyEntity> reader = new JpaPagingItemReader<>();
reader.setEntityManagerFactory(emf);
reader.setQueryString(QUERY);
But it does not work:
[] 2014-09-17 16:31:58,234 ERROR : QuerySyntaxException: unexpected token: * near line 1, column 8 [SELECT * FROM my_data_table]
I also tried SELECT FROM MyDataTable
and SELECT m FROM MyDataTable m
without the star. Same result.
So, how can I execute that hql
query with spring-batch?
By the way: the query works fine in a sql editor like pgAdmin.
Upvotes: 0
Views: 767
Reputation: 12122
SELECT m FROM MyDataTable m
is almost correct (it is valid JPQL
query as long as you have entity calles MyDataTable
). So, it seems that you don't have entity class named MyDataTable
.
As JpaPagingItemReader#setQueryString(String)
accepts JPQL
queries you should make sure that you have entity class for this table and then you should use its name instead MyDataTable
.
By the way - for HQL
queries there's HibernatePagingItemReader.
Upvotes: 1