Spring其实自己没有事务,它使用的是JTA,只不过提供了方面的配置,嵌套事务是最新JTA中才有,还需要JDBC3支持。
(外层)如下:
public void save() throws UserException{
TransactionTemplate tran=new TransactionTemplate(txManager);
tran.execute{
new TransactionCallbackWithoutResult(){
public void doInTransactionWithoutResult(TransactionStatus arg0){
//我的操作
}
}
}
}
在"我的操作"中其中涉及到一个批处理的操作
(内层)批处理的主要代码:
getSqmMapClientTemplate().execute(new SqlMapClientCallback(){
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLExcpetion{
executor.startBatch();
.....
executor.executeBatch();
}
}
请问bang这样外层与内层是不是同一个事务,如果发生异常能不能同时回滚???请指教!
如果说只有嵌套事务才符合"对于外层事务控制来说是一个独立的事务"这个条件,那么我如何
这是肯定的。
至于嵌套事务还是扁平则取决你的JEE版本。
TransactionTemplate tran=new TransactionTemplate(txManager);
tran.execute{
new TransactionCallbackWithoutResult(){
public void doInTransactionWithoutResult(TransactionStatus arg0){
//我的操作
getSqmMapClientTemplate().execute(new SqlMapClientCallback(){
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLExcpetion{
executor.startBatch();
.....
executor.executeBatch();
}
}
}
}
}
}
不好意思我不太明白bang的j2ee版本主要是看什么的版本号。是servlet,jdk?还是什么。
我不知道代码如果直接写成上面的样子能不能知道是嵌套事务还是扁平事务.问题是现在出现了异常没有回滚。
对于事务方面我还不是知道的很多。如果bang能够提供点资料的知更好。