1

我在处理批量创建或修改对象时遇到了一些问题,该对象有一个子对象(实体集合(可能是 1000000 或更多))。

一开始,我尝试直接创建对象:

entite.getEntiteManager(session).createEntite(entite);

但是,一个例外:

maximum open cursors exceeded was thrown.

所以,我尝试了第二种方法:我首先创建父亲,然后通过 250 个列表创建孩子,我影响父亲对他们的引用,而不是我承诺。这就是现在的工作。

问题是:如果在创建孩子的过程中出现了一些问题,那么它只会回滚遇到问题的列表。其他人已经承诺了。

在这种情况下,Spring Batch 对我有用吗?他有没有处理这个问题。

4

1 回答 1

0

The Spring Batch 'chunking' concept will support your retry and failure scenario as you've described. That is, you've created 500 records and a failure occurs and you don't want to lose what you've already got when you restart.

A simple configuration for such a job might be as follows;

<batch:job id="entityCreationJob">
    <batch:step id="entityCreationJob.step1">
        <batch:tasklet>
            <batch:chunk reader="entityReader" writer="entityWriter" commit-interval="250"/>
        </batch:tasklet>
    </batch:step>
</batch:job>

This simple configuration will do the following; - read/create a single record 'per row' (entity.getEntityManager(session).createEntity(e)) - 'commit' the record in 250 record blocks (set by the commit interval)

should you have a failure (lets say, at record 1190), with a commit interval of 250, you will only 'lose' the work of 190 records. the previous 1000 have been committed already to the database. when the application restarts, it will pick up at the 1001 record and continue, committing in 250 record blocks.

to make best use of the commit/retry component, i would suggest you use the JpaItemWriter and either the JpaTransactionManager or a JTA Transaction Manager.

于 2013-07-02T10:21:31.527 回答