PDA

View Full Version : How to get transactional prototype object using declarative trasaction?


Ajay
12-05-2006, 08:12 PM
I am using declarative transaction in my application.

I have wrapped up object 'CreateMyCommand' with a transactional proxy using following configuration

<object id="CommandTxDefinition" type="Spring.Transaction.Interceptor.TransactionProxyFac toryObject, Spring.Data" lazy-init="true">
<property name="PlatformTransactionManager" ref="TransactionManager" />
<property name="TransactionAttributeSource" ref="TransactionAttributeSource" />
<property name="TransactionAttributes">
<name-values>
<add key="Execute*" value="PROPAGATION_REQUIRED" />
</name-values>
</property>
</object>

<object name="CreateMyCommand" parent="CommandTxDefinition">
<property name="target">
<object type="MyProject.Commands.CreateMyCommand, MyProject" singleton="false">
<property name="Dao" ref="Dao"/>
</object>
</property>
</object>


I would like to get prototype instance of 'CreateMyCommand' on every request.
I tried setting singleton="false" on "MyProject.Commands.CreateMyCommand" while setting target property.

But it always return Singleton instance of 'CreateMyCommand'.

Am I missing something here?

rolandz
12-12-2006, 08:10 AM
You just need a command factory object being declared in the spring configuration. Not a command...

Thus you need to provide a factory class or to use following method:

<object type="Spring.Objects.Factory.Config.MethodInvokingFactor yObject, Spring.Core">
<property name="TargetType" value="YourClass, YourAssembly" />

<property name="TargetMethod" value="YourStaticFactoryMethod" />

</object>