Java 方法(JdbcTransactionTemplate)与存储过程共享同一个事务
程序员文章站
2022-05-08 18:41:50
...
如果要让java来管理事务,那么在存储过程里不能写提交(commit work)和回滚(rollback)的代码,否则,存储过程会在一个单独的事务里提交。
Spring的TransactionTemplate和Sybase存储过程共享同一事务要点:
1)确保存储过程里不能写提交(commit work)和回滚(rollback)的代码
2)确保存储过程的事务模式是chained
--change transaction mode to chained since application is forced to use chained transaction mode due to support transaction
--check all stored procedures' transaction mode
sp_procxmode
--change specified stored procedure's transaction mode
sp_procxmode mystoreProcedureXXX, 'chained'
3)在java方法里要用spring的类来调用存储过程
new SimpleJdbcCall(getJdbcTemplate()).withProcedureName("procedureName").execute(inParamMap);
Spring的TransactionTemplate和Sybase存储过程共享同一事务要点:
1)确保存储过程里不能写提交(commit work)和回滚(rollback)的代码
2)确保存储过程的事务模式是chained
--change transaction mode to chained since application is forced to use chained transaction mode due to support transaction
--check all stored procedures' transaction mode
sp_procxmode
--change specified stored procedure's transaction mode
sp_procxmode mystoreProcedureXXX, 'chained'
3)在java方法里要用spring的类来调用存储过程
new SimpleJdbcCall(getJdbcTemplate()).withProcedureName("procedureName").execute(inParamMap);