我使用 smooks 从 .csv 文件中获取记录,文件大小约为单个文件中 30MB 的数据,在这个文件中,大约有 3 万条记录被提取到列表中。
我做了下一个列表使用 subList 划分为子部分 分区大小最多为 2000 。
我想在单个事务中刷新 2000 条记录。但在我的代码中不允许这样。
我正在使用 seam 2.1.2,jap with hibernate,EntityManager,JTA Transactions。
components.xml
<core:init debug="false" jndi-pattern="@jndiPattern@" />
<core:manager concurrent-request-timeout="2000"
conversation-id-parameter="cid" conversation-timeout="120000"
parent-conversation-id-parameter="pid" />
<web:hot-deploy-filter url-pattern="/*.mobee" />
<persistence:entity-manager-factory
installed="@seamBootstrapsPu@" name="entityManagerFactory"
persistence-unit-name="mobeeadmin" />
<persistence:managed-persistence-context
auto-create="true" entity-manager-factory="@seamEmfRef@" name="entityManager"
persistence-unit-jndi-name="@puJndiName@" />
<async:quartz-dispatcher />
<security:identity authenticate-method="#{authenticator.authenticate}" />
<web:rewrite-filter view-mapping="*.mobee" />
<web:multipart-filter create-temp-files="true" max-request-size="28672000" url-pattern="*.seam"/>
<event type="org.jboss.seam.security.notLoggedIn">
<action execute="#{redirect.captureCurrentView}" />
</event>
<event type="org.jboss.seam.security.loginSuccessful">
<action execute="#{redirect.returnToCapturedView}" />
</event>
<mail:mail-session host="localhost" port="25" />
Java 代码:
private List<DoTempCustomers> doTempCustomers;
int partitionSize = 2000;
for (int i = 0; i < doTempCustomers.size(); i += partitionSize) {
String message= tempCustomerMigration(doTempCustomers.subList(i,
i + Math.min(partitionSize, doTempCustomers.size() - i)));
}
@Begin(join=true)
public String tempCustomerMigration(List<DoTempCustomers> list){
PersistenceProvider.instance().setFlushModeManual(getEntityManager());
TempCustomers temp = null;
for(DoTempCustomers tempCustomers:list){
try {
temp=new TempCustomers();
BeanUtils.copyProperties(temp, tempCustomers);
getEntityManager.persist();
getEntityManager.flush();
}
我尝试了很多次这个问题从来没有解决如何在每个事务中将记录刷新到数据库,然后再将服务器响应发送到 GUI
否则我得到异常的一些处理时间是
2012-12-06 17:09:56,380 WARN [com.arjuna.ats.arjuna.logging.arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.BasicAction_58] - Abort of action id -53eff40e:f2db:50c0a356:7d invoked while multiple threads active within it.
2012-12-06 17:09:56,380 WARN [com.arjuna.ats.arjuna.logging.arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.CheckedAction_2] - CheckedAction::check - atomic action -53eff40e:f2db:50c0a356:7d aborting with 1 threads active!
2012-12-06 17:09:56,522 DEBUG [org.jboss.util.NestedThrowable] org.jboss.util.NestedThrowable.parentTraceEnabled=true
2012-12-06 17:09:56,522 DEBUG [org.jboss.util.NestedThrowable] org.jboss.util.NestedThrowable.nestedTraceEnabled=false
2012-12-06 17:09:56,522 DEBUG [org.jboss.util.NestedThrowable] org.jboss.util.NestedThrowable.detectDuplicateNesting=true
2012-12-06 17:09:56,524 INFO [STDOUT] [Mobee]- WARN 2012-12-06 17:09:56,524 [] JDBCExceptionReporter - SQL Error: 0, SQLState: null
2012-12-06 17:09:56,525 INFO [STDOUT] [Mobee]-ERROR 2012-12-06 17:09:56,524 [] JDBCExceptionReporter - Transaction is not active: tx=TransactionImple < ac, BasicAction: -53eff40e:f2db:50c0a356:7d status: ActionStatus.ABORTING >; - nested throwable: (javax.resource.ResourceException: Transaction is not active: tx=TransactionImple < ac, BasicAction: -53eff40e:f2db:50c0a356:7d status: ActionStatus.ABORTING >)
2012-12-06 17:09:56,545 INFO [STDOUT] [Mobee]-ERROR 2012-12-06 17:09:56,527 [] AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
对于这个例外,我在 google 中找到了 sol 以增加 jboss--service.xml 中的 TransactionTimeout 对我来说,即使增加超时参数也没有用。