JAVA 代码和Procedure 不是同一个事物
场景1:
存储过程显式的提交事务,java代码发生异常,存储过程的事物不会回滚
java 代码调用 oracle procedure 伪代码;
procedure test_transaction
asbegin
insert into table value(2,’name2’);
commit;
end test_transaction;public class TransactionDemoBoImpl{
/*
Spring 管理声明式事物
*/
public void addTableRecord{
insert into table value(1,’name1’);
call {test_transactio};
int a = 1/0;
}
}场景2:
存储过程未显式的提交事务,java代码发生异常,存储过程的事物会回滚
procedure test_transaction
as
begin
insert into table value(2,’name2’);
end test_transaction;public class TransactionDemoBoImpl{
/*
Spring 管理声明式事物
*/
public void addTableRecord{
insert into table value(1,’name1’);
call {test_transactio};
int a = 1/0;
}
}场景3:
存储过程显式的提交事务,java代码发生异常,存储过程的事物不会回滚,并且调用存储过程前的java数据库操作会回滚
procedure test_transaction
as
begin
insert into table value(2,’name2’);
commit;
end test_transaction;public class TransactionDemoBoImpl{
/*
Spring 管理声明式事物
*/
public void addTableRecord{
insert into table value(1,’name1’);
call {test_transactio};
int a = 1/0;//调用存储过程前的javadb操作会回滚
insert into table value(3,’name3’);
}}