【发布时间】:2014-10-09 00:12:35
【问题描述】:
MySQL 社区服务器 v5.6.19
JPA 2
EclipseLink
WildFly 8
Java EE 7
JDK 1.8
容器管理的持久性
我正在尝试从 XML 文件加载大量参考数据并将其存储在 MySQL 数据库中。
总共有大约 60,000 条记录需要写入数据库。
前 7,500 条左右的记录一切正常,但随后我得到以下信息:-
00:06:37,157 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff0a00000b:2d6361a7:5435c20e:22 in state RUN
00:06:37,161 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012095: Abort of action id 0:ffff0a00000b:2d6361a7:5435c20e:22 invoked while multiple threads active within it.
00:06:37,161 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012108: CheckedAction::check - atomic action 0:ffff0a00000b:2d6361a7:5435c20e:22 aborting with 1 threads active!
00:06:37,184 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012121: TransactionReaper::doCancellations worker Thread[Transaction Reaper Worker 0,5,main] successfully canceled TX 0:ffff0a00000b:2d6361a7:5435c20e:22
00:06:37,193 ERROR [org.jboss.as.ejb3] (default task-38) javax.ejb.EJBTransactionRolledbackException: JBAS011469: Transaction is required to perform this operation (either use a transaction or extended persistence context)
00:06:37,193 ERROR [org.jboss.as.ejb3.invocation] (default task-38) JBAS014134: EJB Invocation failed on component MyItemDAO for method public java.lang.Object model.dao.BaseDAO.update(java.lang.Object): javax.ejb.EJBTransactionRolledbackException: JBAS011469: Transaction is required to perform this operation (either use a transaction or extended persistence context)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleInCallerTx(CMTTxInterceptor.java:163) [wildfly-ejb3-8.1.0.CR2.jar:8.1.0.CR2]
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:253) [wildfly-ejb3-8.1.0.CR2.jar:8.1.0.CR2]
at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:342) [wildfly-ejb3-8.1.0.CR2.jar:8.1.0.CR2]
at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:239) [wildfly-ejb3-8.1.0.CR2.jar:8.1.0.CR2]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
然后是更多的警告和错误。所有后续插入语句都失败。
我根据 ARJUNA 错误代码进行了搜索,但我找到的答案似乎表明数据库或表由于 mysqldump 而被锁定。这不是我的情况 - 没有正在进行的 mysqldump。
我看到的另一个建议是 MySQL 连接的数量可能已用尽,但我不确定 JPA 是如何分配连接的。我有两个正在更新的表,一旦从源数据文件中完全填充每个实体,我就会合并然后刷新它。
我的数据文件和处理看起来像这样......
<!-- Reference data file -->
<!-- Contains 1 x elem_1 record, approx 1000 elem_2 records, and approx 60,000 elem_3 records -->
<!-- There is a varying number of elem_3 records per elem_2 record -->
<elem_1 attr1="" attr2=""> <!-- Create detached elem_1 entity -->
<!-- Persist elem_1 entity and flush elem_1 EM -->
<elem_2 attr1=""> <!-- Create detached elem_2 entity -->
<val_1>Value..</val_1> <!-- Add value to detached entity -->
<val_2>Value..</val_2> <!-- Add value to detached entity -->
<val_3>Value..</val_3> <!-- Add value to detached entity -->
<!-- Persist elem_2 entity and flush elem_2 EM -->
<elem_3 attr1="" attr2="" attr3=""> <!-- Create detached elem_3 entity -->
<child_1>Value..</child_1> <!-- Add value to detached entity -->
<child_2>Value..</child_2> <!-- Add value to detached entity -->
<child_3>Value..</child_3> <!-- Add value to detached entity -->
</elem_3> <!-- Persist elem_3 entity and flush elem_3 EM -->
<!-- Repeat above elem_3 process for all elem_3 records -->
<!-- Call clear() on elem_3 EM -->
</elem_2> <!-- Flush elem_2 EM then call clear() on elem_2 EM -->
<!-- Repeat above elem_2 process for all elem_2 records -->
</elem_1>
谁能建议这可能是什么原因造成的?更重要的是,我该如何解决它,以便我可以加载所有数据?
【问题讨论】:
-
你看到mysql的错误日志了吗?
-
Transaction is required to perform this operation (either use a transaction or extended persistence context)。您是否在打开事务时调用刷新? -
@Widrogo - MySQL 似乎没有创建日志文件(或者至少我找不到它们)所以我必须检查配置并回复你。
-
@uaiHebert - 我在每个实体上使用 Container Managed Persistence 和 PersistenceContext 注入。前 7,500 次迭代没有问题(都在同一个 DAO 上调用相同的 merge(...) 和 flush(...) 方法),所以我认为这与丢失的事务无关。我意识到这是错误消息所暗示的,但我认为这是在数据库连接(以及因此实体管理器和任何事务支持)失败之后。
标签: mysql jpa eclipselink wildfly