Java 异步和事务方法

Java 异步和事务方法,java,spring,asynchronous,spring-async,Java,Spring,Asynchronous,Spring Async,我有一个从文件导入数据库的web应用程序。 该方法是异步和事务性的,用于读取和插入对象。 问题是导入方法需要5或6分钟。如果在不关闭事务的情况下抛出两次import方法,则第二个方法将获得重复的插入ID。第一次运行很好,但是当您提交第二次运行时失败。这是我的代码: @Controller public class IndexController { @Autowired private fooServicio fService; @RequestMapping(val

我有一个从文件导入数据库的web应用程序。 该方法是异步和事务性的,用于读取和插入对象。 问题是导入方法需要5或6分钟。如果在不关闭事务的情况下抛出两次import方法,则第二个方法将获得重复的插入ID。第一次运行很好,但是当您提交第二次运行时失败。这是我的代码:

@Controller
public class IndexController {

    @Autowired
    private fooServicio fService;

    @RequestMapping(value="/", method = RequestMethod.GET)
    public final ModelAndView printIndex(MultipartFile file) 
    {
        ModelAndView view = new ModelAndView("index");


        foService.import(file);

        view.addObject("message", "The file is loading"); 
        return view;        
    }
}

@Service
@Transactional(readOnly = true)
public class FooServiceImpl implements FooService {

    @Async
    @Override
    @Transactional(readOnly = false)
    public final void import(final MultipartFile file) throws ServiceException {
            //Read file and inserts
    }
} 

我怎样才能解决这个问题?有没有一种方法可以用尾部管理异步方法?对于一个直到另一个完成才开始的方法。

如何生成ID?我使用hibernate和oracle进行序列。我认为应该使用AsyncTaskExecutor来运行异步进程