openJPA批处理更新模式 [英] openJPA batch update pattern

查看:87
本文介绍了openJPA批处理更新模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更新数千个实体,并且逻辑不能放入SQL语句中.使用非托管JPA时,我使用的模式是:

I need to update thousands of Entities and the logic can not be put into a SQL statement. When using non-managed JPA the pattern I use is:

long commitThreshold = 100;  // or other appropriate value
try {
  em.beginTransction().begin();
  for(list of entities to be modified) {
      // retrieve current Entity
      // modify current Entity 

      if((++modifiedEntityCount % commitThreshold) == 0) {
        em.getTransaction().commit();
        em.getTransaction().begin();
      }
  }
  if(em.getTransaction().isActive()) {
      em.getTransaction().commit();
  }
catch () {
}
finally {
    // cleanup 
}

在托管环境中,这会导致

In a managed environment this results in a

java.lang.IllegalStateException: Transaction management is not available for container managed EntityManagers.

使用容器管理的事务和蓝图时,这种用例的最佳模式是什么?我的特定环境是karaf 3.0.5和openJPA 2.3.x(如果需要的话).

What is a good pattern for this type of use case when using container managed transactions and blueprint? My specific environment is karaf 3.0.5 and openJPA 2.3.x if it matters.

推荐答案

更新您的persistence.xml配置以使用语句批处理

Update your persistence.xml configuration to use statement batching

OpenJPA语句批处理

这篇关于openJPA批处理更新模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆