【问题标题】:openJPA batch update patternopenJPA 批量更新模式
【发布时间】:2023-04-09 22:00:01
【问题描述】:

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

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 
}

在托管环境中,这会导致

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

在使用容器管理事务和蓝图时,这种类型的用例有什么好的模式?我的具体环境是 karaf 3.0.5 和 openJPA 2.3.x 如果重要的话。

【问题讨论】:

    标签: jpa openjpa karaf


    【解决方案1】:

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

    OpenJPA Statement batching

    【讨论】:

      猜你喜欢
      • 2019-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-16
      • 1970-01-01
      相关资源
      最近更新 更多