2016-03-26 17 views
2

何千ものエンティティを更新する必要があり、ロジックをSQL文に入れることはできません。非管理JPAを使用する場合は、私が使用パターンは次のとおりです。管理された環境でopenJPAバッチ更新パターン

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です。

答えて

関連する問題