単一の永続ユニットで OpenJPA 2.0 を使用しています。
私の persistence.xml では、構成を使用してtransaction-type="RESOURCE_LOCAL"
手動でトランザクションを管理することを選択しました。
さて、以下のコードで、 aPersistenceException
がスローされた (そしてキャッチされた) 場合、どのようにトランザクションをクリーンアップすればよいでしょうか?
try {
entityManager.getTransaction().begin();
MyClassPO myClassPO = (MyClassPO) entityManager
.createQuery("select bn from myClassPO bn where bn.xxx = :xxx")
.setParameter("xxx", xxx)
.getSingleResult(); // NoResultException gets thrown here
... do some more stuff ...
entityManager.getTransaction().commit();
} catch (PersistenceException e) {
// what should I do with the open transaction here ??
logger.error(e);
throw new MyOtherException(e);
}
次回同じ操作を実行するとエラーメッセージが表示されるため、トランザクションが自動的にクリーンアップされていないことを知っていますThis operation cannot be performed while a Transaction is active.
ブロックを入れるだけentityManager.getTransaction().rollback();
の簡単なものですか?catch