using (var ts = Transaction.Open(TransactionOpenMode.New))
{
    var qqq = new DocEntity(Guid.NewGuid());

    using (CurrentSession.Pin(qqq))
    {
        using (var ti = Transaction.Open(TransactionOpenMode.New))
        {
            var qew = Query.All<Icon>().ToArray();

            ti.Complete();
        }
    }

    ts.Complete();
}

So, this code fails with

System.InvalidOperationException : Can not persist: there are pinned entities.

But I dont really understand, why do you persist here?

Moreover, we have a strange exception with this situation in our project:

Test(s) failed. Xtensive.Storage.StorageException : Error 'Unknown'. Original message: Cannot roll back s2. No transaction or savepoint of that name was found.
  ----> System.Data.SqlClient.SqlException : Cannot roll back s2. No transaction or savepoint of that name was found.
   at Xtensive.Storage.Providers.Sql.Driver.RollbackToSavepoint(Session session, SqlConnection connection, String name)
   at Xtensive.Storage.Providers.Sql.SessionHandler.RollbackToSavepoint(String name)
   at Xtensive.Storage.Session.RollbackTransaction(Transaction transaction)
   at Xtensive.Storage.Transaction.Rollback()
   at Xtensive.Storage.TransactionScope.Dispose()
   at Werp.Controller.Services.DocumentDataObject`1.StartOperation(DocumentOperation documentOperation, Guid documentId, ParameterBase parameter) in d:\BuildAgents\1\work\f27cc1092d3e1cc2\Werp.Controller.Services\DocumentDataObject.cs:line 257
   at Werp.Controller.Services.DocumentDataObject`1.StartOperation(Type operationType, Guid documentId, ParameterBase parameter) in d:\BuildAgents\1\work\f27cc1092d3e1cc2\Werp.Controller.Services\DocumentDataObject.cs:line 213
   at Werp.Controller.Services.DocumentDataObject`1.StartOperation(Type operationType, Guid documentId) in d:\BuildAgents\1\work\f27cc1092d3e1cc2\Werp.Controller.Services\DocumentDataObject.cs:line 74
   at Werp.Controller.Services.DocumentOperationBase`1.Exec[TOperation](DocumentBase doc) in d:\BuildAgents\1\work\f27cc1092d3e1cc2\Werp.Controller.Services\DocumentOperationBase{TDocument}.cs:line 84
   at Tests.Controller.Models.SampleDocDocumentOperation.Finish(OperationContext context) in d:\BuildAgents\1\work\f27cc1092d3e1cc2\Tests.Controller\Models\SampleDocDocumentOperation.cs:line 51
   at Werp.Controller.Services.DocumentDataObject`1.<>c__DisplayClass19.<FinishOperation>b__15(IDocumentOperation o) in d:\BuildAgents\1\work\f27cc1092d3e1cc2\Werp.Controller.Services\DocumentDataObject.cs:line 345
   at Werp.Controller.Services.DocumentDataObject`1.ExecuteOperationMethod(String operation, T[] documents, ParameterBase parameter, Action`1 func) in d:\BuildAgents\1\work\f27cc1092d3e1cc2\Werp.Controller.Services\DocumentDataObject.cs:line 531
   at Werp.Controller.Services.DocumentDataObject`1.FinishOperation(Guid documentId, ParameterBase parameter, IDictionary`2 values) in d:\BuildAgents\1\work\f27cc1092d3e1cc2\Werp.Controller.Services\DocumentDataObject.cs:line 345
   at Werp.Controller.Services.DocumentDataObject`1.FinishOperation(Guid documentId) in d:\BuildAgents\1\work\f27cc1092d3e1cc2\Werp.Controller.Services\DocumentDataObject.cs:line 283
   at Werp.Controller.Services.DocumentOperationBase`1.Exec[TOperation](TDocument doc) in d:\BuildAgents\1\work\f27cc1092d3e1cc2\Werp.Controller.Services\DocumentOperationBase{TDocument}.cs:line 55
   at Tests.Controller.DocumentTest.OperationExecutionTest() in d:\BuildAgents\1\work\f27cc1092d3e1cc2\Tests.Controller\DocumentTest.cs:line 45
--SqlException
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest)
   at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest transactionRequest, String transactionName, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
   at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransaction(TransactionRequest transactionRequest, String name, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
   at System.Data.SqlClient.SqlInternalTransaction.Rollback(String transactionName)
   at System.Data.SqlClient.SqlTransaction.Rollback(String transactionName)
   at Xtensive.Sql.SqlServer.Connection.RollbackToSavepoint(String name)
   at Xtensive.Storage.Providers.Sql.Driver.RollbackToSavepoint(Session session, SqlConnection connection, String name)

asked Feb 02 '11 at 07:26

xumix's gravatar image

xumix
425757682


One Answer:

But I dont really understand, why do you persist here?

Persist is required before start and commit of any nested transaction:

  • If we won't do it @ start, unpersisted state can be flushed inside nested transaction. If it will be rolled back, you won't see what you expect here, since the changes, that were actually happen before its start are rolled back.
  • The reason we flush the changed before commit of nested transaction is absolutely the same.

Moreover, we have a strange exception with this situation in our project: ...

Most likely, it happens because the original error ("can't persist, there are pinned entities") is suppressed either by your or by our own code. Is there InnerException? Could you publish a result of exception.ToString()?

answered Feb 03 '11 at 23:31

Alex%20Yakunin's gravatar image

Alex Yakunin
29714412

edited Feb 03 '11 at 23:34

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA