According to the documentation http://www.telerik.com/help/openaccess-orm/telerik.openaccess-telerik.openaccess.itransaction-begin.html I should be able to start a second transaction within an existing one. However, when I try to do that, I am getting the following exception: 'Transaction already active'.
Is there a way to have nested transactions in OpenAccess (as the documentation suggest)?
What I am trying to achieve is a unit test were I first 'save' the data within the nested transaction, then commit it and then retrieve the data within the outer transaction. Then I rollback everything. This way I know the code that writes to the db and the query works (see pseudo code below).
Thank you in advance, Eyal.
scope.Transaction.Begin(); |
scope.Transaction.Begin(); |
StoreData(); |
scope.Transaction.Commit(); |
RetrieveData(); // if OK, then the test is passed! |
scope.Transaction.Rollback(); |
9 Answers, 1 is accepted
This is old information left from our java implementation of the old product. Telerik OpenAccess ORM does not support nested transactions and this document is outdated. Thank you for bringing this to our attention. Your Telerik points were updated.
Best wishes,
Petar
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Can you suggest another way for achieving a unit test for my case.
One of the reasons we have chosen OpenAccess as our ORM tool is unit testing.
If there is no way to apply our unit tests with OA, we might have to consider another tool...
Eyal.
You can use IObjectScope.Transaction.Flush(). This will temporarily flush all data in the current transaction to the SQL server without committing it. So when you call IObjectScope.Transaction.Rollback() everything from the flush will be removed. I hope that this will help you solve your problem. Let me know if I can assist you further.
All the best,
Petar
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Thank you for the response. IObjectScope.Transaction.Flush() does exactly what we were looking for.
As I've mentioned, this was a crucial element in out unit testing strategy, and this solution will allow us to move forward.
You might want to write a quick article on how to achieve unit testing using this mechanism so that others can do the same.
Thanks again, Eyal.
We are actively working on expanding our documentation(articles, blog posts, knowledge bases, code libraries) and such suggestions are always welcomed. We will most certainly add this topic as we feel that you are right and such topic might be useful for other customers as well. Also if you feel that we are missing content in other areas please do not hesitate to point them to us and we will address them as soon as possible.
Kind regards,
Petar
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
sorry, but 7 month after the problem in the documentation was posted and confirmed by you, the document for the Begin-Method is still saying:
"Begins the transaction. If the transaction is already active, a new nesting level ist started."
But instead i still receive an exception 'Transaction already active'
Nested transactions would be very useful!
Please explain the strategy for this topic!
Would you implement nested transactions?
Would you change the documentation?
Best regards
Dirk
You are correct. The documentation was indeed not updated correctly. From now on the description will state the following:
Begins a new transaction. If there is another transaction already running an exception will be thrown.
Currently we do not plan support for nested transactions.
Sincerely yours,
Petar
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Unfortunately our online help is out of date. We will do our best to update it as soon as possible. For now you should use the installed help in .chm format, part of the latest internal build of the product released on the 10th of June(version 2010.610.1).
If you need more information regarding transactions please refer to the following topics:
-Programmers Guide/OpenAccess ORM Visual Designer/Programming Guide/OpenAccess Tasks/Defining a Domain Model/How to: Work with Transactions - This topic will show you how to perform transactions by using the OpenAccessContext. Please consider that this part of the help is still under development and will be ready for our next major release. We are planning to extend especially this topic.
-Programmers Guide/OpenAccess ORM Classic/Programming with OpenAccess/Transactions - note that the information in this section regards the classic version of Telerik OpenAccess ORM (Reverse Mapping/Forward Mapping Wizards/IObjectScope).
If you feel there is a missing content in the current version of the help, do not hesitate to share with us and we will address it.
Regards,
the Telerik team