简体   繁体   English

提交过程中的延迟(使用JPA / JTA)

[英]Delay during commit (using JPA/JTA)

I would like to ask you for help with following problem. 我想问您以下问题的帮助。 I have method: 我有方法:

String sql = "INSERT INTO table ...."
Query query = em.createNativeQuery(sql);
query.executeUpdate();
sql = "SELECT max(id) FROM ......";
query = em.createNativeQuery(sql);
Integer importId = ((BigDecimal) query.getSingleResult()).intValue();

for (EndurDealItem item : deal.getItems()) {
        String sql2 = "INSERT INTO another_table";
        em.createNativeQuery(sql2).executeUpdate();
    }

And after executing it, data are not commited (it takes like 10 or 15 minutes until data are commited). 并且在执行之后,不会提交数据(提交数据大约需要10或15分钟)。 Is there any way how to commit data explicitly or trigger commit? 有什么方法可以显式提交数据或触发提交? And what causes the transaction to remain uncommited for such a long time? 是什么导致交易长时间未提交呢?

The reason we use nativeQueries is, that we are exporting data on some shared interface and we are not using the data anymore. 我们使用nativeQueries的原因是,我们正在某个共享接口上导出数据,并且不再使用该数据。

I would like to mention, that the transaction is Container-Managed (by Geronimo). 我想提一下,该事务是由容器管理的(由Geronimo进行)。 EntityManager is created via linking: EntityManager是通过链接创建的:

 @PersistenceContext(unitName = "XXXX", type = PersistenceContextType.TRANSACTION)
 private EntityManager em;

Use explicitly the transaction commit: 显式使用事务提交:

EntityManager em = /* get an entity manager */;
em.getTransaction().begin();
// make some changes
em.getTransaction().commit();

This should work. 这应该工作。 The time of execution of all operation between .begin() and .end() depends of course also from the cycle you're performing, the number of row you're inserting, from the position of the database (the speed of the network matters) and so on... 当然,.begin()和.end()之间所有操作的执行时间还取决于执行的周期,要插入的行数,数据库的位置(网络的速度)。事项),依此类推...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM