【发布时间】:2017-11-09 08:28:23
【问题描述】:
我有一个执行一些 DB 操作的 EJB,然后在执行更多 DB 操作的 JNDI 查找之后调用另一个 EJB。这第二个 EJB 调用可能会引发一些异常,即 PersistenceException(我查看了此异常将事务标记为仅回滚的代码)。有什么办法可以避免事务回滚?下面是总结问题的代码。预先感谢。
public class Test {
ejbMthod1() {
// This method run under transaction
// Do some DB operation like update\delete
if(somecondition) {
try {
// JNDI lookup for ejb2
ejbMethod2();
}
catch(Exception ex){
// Will catching the exception here save the Transaction from rollback ?
// Is there any way I can avoid this rollback just by handling proper exceptions ?
}
}
}
}
class Test2 {
ejbMethod2() {
// Run under same transaction as caller
// do some DB operation which can throw many exception i.e. PersistenceException.
}
}
【问题讨论】:
-
提示:如果您的问题已解决,请考虑接受。
标签: java exception transactions ejb ejb-3.0