Spring批处理JpaPagingItemReader(可能)在使用SELECT本机查询时从数据库中删除行 [英] Spring batch JpaPagingItemReader (possibly) removes rows from the database while using SELECT native query

查看:2538
本文介绍了Spring批处理JpaPagingItemReader(可能)在使用SELECT本机查询时从数据库中删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用JpaPagingItemReader执行本机SELECT查询。但是,当我运行它时,从我的数据库中删除了一些记录(我在使用mysql控制台执行批处理作业前后对其进行了检查)。我与MySQL数据库进行通信的唯一地方是当我读取数据时 - 像这样:

  @Autowired 
EntityManagerFactory entityManagerFactory

@Value('$ {integration.date.value}')
字符串日期


@Bean
JpaPagingItemReader<条目> (){
JpaPagingItemReader jpaPagingItemReader = new JpaPagingItemReader< Entry>()
jpaPagingItemReader.setEntityManagerFactory(entityManagerFactory)
jpaPagingItemReader.setQueryProvider(createQueryProvider())
jpaPagingItemReader.setPageSize(500)
jpaPagingItemReader.afterPropertiesSet()
jpaPagingItemReader
}

private JpaNativeQueryProvider< Entry> createQueryProvider(){
String query =SELECT distinct * FROM entry e WHERE e.entry_formal_category in('FIL','SER')+
and e.entry_categories not regexp'DZI | INN | DOK'和e.entry_date = \'+ date +\'+
GROUP BY e.entry_title ORDER BY e.entry_id

JpaNativeQueryProvider< Entry> queryProvider = new JpaNativeQueryProvider< Entry>()
queryProvider.setSqlQuery(query)
queryProvider.setEntityClass(Entry)
queryProvider.afterPropertiesSet()
queryProvider
}

我对这种行为感到非常震惊 - 每次执行工作时,我都会丢失10到50条记录数据库。是否有可能是由分页本机查询结果引起的?



编辑:有点更新。当我将页面大小设置为1500(这是一个大小,将保存在一页上的所有行),问题不会发生。它看起来可能是一个弹簧批次的bug。

解决方案

好的 - 我错过了一个地方,我修改了一个Entry对象,并且在获取另一个页面之前更改传播到了数据库。春季批次工作得很好 - 这是我的错。问题解决了 - 谢谢! :)

I'm trying to perform a native SELECT query with JpaPagingItemReader. However, when i run it, some records are deleted from my database (I checked it before and after the batch job execution with mysql console). The one and only place where I communicate with the MySQL database is when I read the data - like this:

@Autowired
EntityManagerFactory entityManagerFactory

@Value('${integration.date.value}')
String date


@Bean
JpaPagingItemReader<Entry> entryJpaPagingItemReader() {
    JpaPagingItemReader jpaPagingItemReader = new JpaPagingItemReader<Entry>()
    jpaPagingItemReader.setEntityManagerFactory(entityManagerFactory)
    jpaPagingItemReader.setQueryProvider(createQueryProvider())
    jpaPagingItemReader.setPageSize(500)
    jpaPagingItemReader.afterPropertiesSet()
    jpaPagingItemReader
}

private JpaNativeQueryProvider<Entry> createQueryProvider() {
    String query = "SELECT distinct * FROM entry e WHERE e.entry_formal_category in ('FIL','SER') " +
            "and e.entry_categories not regexp 'DZI|INN|DOK' and e.entry_date = \'" + date + "\'" +
            " GROUP BY e.entry_title ORDER BY e.entry_id"

    JpaNativeQueryProvider<Entry> queryProvider = new JpaNativeQueryProvider<Entry>()
    queryProvider.setSqlQuery(query)
    queryProvider.setEntityClass(Entry)
    queryProvider.afterPropertiesSet()
    queryProvider
}

I'm quite shocked about this behavior - each time i execute the job i loose about 10 to 50 records from the database. Is it possible that the problem is caused by paging the native query results?

EDIT: a little update. When I set the pageSize to 1500 (it is a size, that will hold all rows on one page) the problem doesn't occur. It looks that it may be a spring-batch bug.

解决方案

Ok - i have missed one place where I modified an Entry object and the changes propagated to the database before fetching another page. Spring batch works perfectly well - it was my fault. Problem solved - thank you! :)

这篇关于Spring批处理JpaPagingItemReader(可能)在使用SELECT本机查询时从数据库中删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆