SQL Server 2005 - 无法回滚嵌套事务

时间:2009-11-09 09:40:08

标签: sql-server-2005 hibernate c3p0

有时,我在执行存储过程时从SQL Server 2005获得以下内容:

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot roll back T1. No transaction or savepoint of that name was found.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(Unknown Source)
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeUpdate(Unknown Source)
    at com.mchange.v2.c3p0.impl.NewProxyCallableStatement.executeUpdate(NewProxyCallableStatement.java:2160)
    at com.sm.persistence.dao.TransactionRejectDAO.callSpMoveTransaction(TransactionRejectDAO.java:631)
    ... 6 more

有什么想法吗?

当连接池机制尝试关闭准备好的语句时:

Nov 9, 2009 9:32:55 AM com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement close
WARNING: SQLServerPreparedStatementID:201 ( ConnectionID:139 TransactionID:0x1A00000039000000): Error (ignored) closing PreparedHandle:0
com.microsoft.sqlserver.jdbc.SQLServerException: The server failed to resume the transaction. Desc:390000001a.
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(Unknown Source)
    at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(Unknown Source)
    at com.microsoft.sqlserver.jdbc.TDSParser.parse(Unknown Source)
    at com.microsoft.sqlserver.jdbc.TDSParser.parse(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$1PreparedHandleClose.doExecute(Unknown Source)
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.closePreparedHandle(Unknown Source)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.close(Unknown Source)
    at com.mchange.v1.db.sql.StatementUtils.attemptClose(StatementUtils.java:41)
    at com.mchange.v2.c3p0.stmt.GooGooStatementCache.synchronousDestroyStatement(GooGooStatementCache.java:413)
    at com.mchange.v2.c3p0.stmt.GooGooStatementCache.closeAll(GooGooStatementCache.java:351)
    at com.mchange.v2.c3p0.impl.NewPooledConnection.closeAllCachedStatements(NewPooledConnection.java:673)
    at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:543)
    at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:234)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:470)
    at com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:964)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
Nov 9, 2009 9:32:55 AM com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement close
WARNING: SQLServerPreparedStatementID:186 ( ConnectionID:139 TransactionID:0x1A00000039000000): Error (ignored) closing PreparedHandle:0

存储过程包含嵌套事务T1,我认为这是不必要的。这可能是问题吗?

由于

2 个答案:

答案 0 :(得分:1)

第一个错误是由于你有一个名为的嵌套事务,你试图回滚到 - 命名一个嵌套事务(命名意味着键入类似“BEGIN TRANSACTION”的东西,在允许使用您的case = T1),但不支持回滚到命名的嵌套事务并导致错误。

有关详细信息,请参阅this主题。

答案 1 :(得分:1)

如果必须回滚嵌套事务,则可以使用SAVE Transaction。 见here