View Full Version : Attribute Based Transasction Handling
bchoi
09-19-2006, 06:13 PM
Anybody has working example? I tried with following it seems like execution
is not under transaction. (no log output)
[Transaction()]
public void Save()
{
Department dept = session.Load<Department>(10);
session.Save(dept);
Department deptReadback = session.Load<Department>(10);
Assert.AreEqual(dept.Location, deptReadback.Location);
}
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns='http://www.springframework.net'>
<object id="departmentTestTarget" type="BLLTest.DepartmentTest, BLLTest">
<property name="Session" ref="session" />
</object>
<object id="session" type="DAL.Session, DAL">
</object>
<!-- Declarative Transaction based on AOP -->
<object id="departmentTest"
type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
<property name="Target" ref="departmentTestTarget"/>
<property name="InterceptorNames">
<value>transactionInterceptor</value>
</property>
</object>
<object id="transactionInterceptor"
type="Spring.Transaction.Interceptor.TransactionIntercep tor, Spring.Data">
<property name="TransactionManager" ref="transactionManager"/>
<property name="TransactionAttributeSource" ref="transactionAttributeSource"/>
</object>
<object id="transactionManager"
type="Spring.Data.TxScopeTransactionManager, Spring.Data">
</object>
<object id="transactionAttributeSource"
type="Spring.Transaction.Interceptor.AttributesTransacti onAttributeSource, Spring.Data">
</object>
</objects>
Mark Pollack
09-20-2006, 02:01 AM
Hi,
There are examples of ADO.NET usage with transaction management in the Spring.Data.Integration.Tests project. In particular, AutoDeclarativeTxTests.cs (http://fisheye1.cenqua.com/browse/springnet/Spring.Net/test/Spring/Spring.Data.Integration.Tests/Data) shows usage of AdoTemplate and declarative transaction management. The associated config file shows how to configure the container. I apologize up front for the lack of docs.
To get declarative tx mgmt for ADO.NET in .NET 1.1 you need to use AdoTemplate, which provides a bunch of helper methods to do straight up data access, a minimal o/r mapping framework, as well as DataSet functionality. Most likely your Session implemenation is using the "plain" ADO.NET API and as such is not aware of any transaction in the calling context set by the transactional AOP advice.
AdoTemplate is aware of a transaction that is started by the AOP framework. (On a side note, with .NET 1.1 you will probably be successful using the "plain" ADO.NET API by using the ServiceDomainPlatformTransactionManager that uses EnterpriseServices to manage transactions, but this comes at a cost of always using the distributed transaction coordinator and hence pays the price of two two-phase commits protocol even when using a single database. It is much better to use "local" transactions).
If you are using .NET 2.0, you can use spring's declarative tx mgmt with a TxScopeTransactionManager since the "plain" ADO.NET APIs are aware of a transaction created via the new TransactionScope functionality.
Since there isn't a default "out of the box" ADO.NET provider API in .NET 1.1 (unlike 2.0) I don't think we are able to provide a "TransactionAware DataProvider", like is done in Spring.Java using the TransactionAwareDataSource.
Anyway, this might be a bit overwhelming, let me know if you need some additional help. Again, apologies about the docs. There are two presentations on the Spring.NET home page about the data access support. If you haven't read through those already, take them for a spin.
Cheers,
Mark
bchoi
09-20-2006, 06:44 PM
Thank you Mark for detailed explanation. I am suing .net 2.0. That is way I used TxScopeTransactionManager. It seems like proxying part is ok but intercepting part is not working. Am I using correct attibute or Do I have to use TransactionProxyFactoryObject instead plain one?
Also I am using IBatis.Net with Spring.Net which I believe using ADO.NET.
Finally If transaction is working do I see that in log file (I set to level as "ALL")?
bchoi
09-21-2006, 07:46 PM
I found what is wrong with it. My class doesn't implement interface so I have to make save mehtod as virtual. But now I have another problem. I am using
txScopeTransactionManager now it crases at "commit point".
protected override void DoCommit(DefaultTransactionStatus status)
{
PromotableTxScopeTransactionObject txObject =
(PromotableTxScopeTransactionObject)status.Transac tion;
try
{
txObject.TransactionScope.Complete();
txObject.TransactionScope.Dispose(); }
catch (Exception e)
{
//TODO provide more accurate exception mappings.
throw new Spring.Transaction.TransactionSystemException("Failure on Promotable Transaction Scope Commit", e);
}
}
it crashes at "txObject.TransactionScope.Dispose();".
Mark Pollack
09-22-2006, 03:53 PM
Hi,
Can you provide the exception message as well as some more details of your data access code, in particular the ibatis stuff. Send me a private forum message with the code or minimal example that has the same behavior - that would help alot!
I would imagine that wrapping iBatis code with a TxScope is ok, it would be good to check that in a straightfoward code style. From what I see it looks like "Promotable Single Phase Enlistment" isn't working, are you using SqlServer 2005? This is the only db that supports that functionality now AFAIK. If you are not using SqlServer 2005 we will need to write some iBatis support code that will propagate the current tx scope into the iBatis calls, similar to HibernateTemplate.
Cheers,
Mark
bchoi
09-22-2006, 05:46 PM
Hi. Thank you for your prompt reply.
Native ado.net code was ok. (I am using oracle server).
Looks like iBatis session (or Mapper() singleton) is interfering with
spring transaction manager. Also I failed to use AdoPlatformTransactionManager and ServiceDomainPlatformManager in XML config. (Context handler error). Currently I am just intercepting transaction attribute and manually handling transaction.
Mark Pollack
09-22-2006, 10:57 PM
Hi,
I will need to investigate iBatis integration then. I can't look into this until next week sometime. If you can post your iBatis code you use to manually handle the tx started by spring that would be appreciated. What version of iBatis are you using?
Cheers,
Mark
vBulletin® v3.7.3, Copyright ©2000-2009, Jelsoft Enterprises Ltd.