在下面描述的情况下,在 JDO 中,AftermethodB()
被执行(已从 调用methodA()
),如果发生异常,是否会在提交中和或就像在提交中methodA()
发生的代码一样进行回滚。注意:PersistenceManager 按需创建并存储在 ThreadLocal 中methodA()
methodB()
methodA()
methodB()
methodA() {
PersistenceManager mgr = getPersistenceManager( );
Transaction trans;
trans = mgr.currentTransaction( );
try {
trans.begin( );
methodB();
//some delete/update code
// An exception occurs
trans.commit( );
}
catch( Exception e ) {
e.printStackTrace( );
}
finally {
if( trans.isActive( ) ) {
trans.rollback( );
}
mgr.close( );
}
}
methodB() {
PersistenceManager mgr = getPersistenceManager( );
Transaction trans;
trans = mgr.currentTransaction( );
try {
trans.begin( );
//code
trans.commit( );
}
catch( Exception e ) {
e.printStackTrace( );
}
finally {
if( trans.isActive( ) ) {
trans.rollback( );
}
mgr.close( );
}
}