PDA

View Full Version : non-singleton using with TransactionProxyFactoryObject


floyd
08-11-2007, 06:14 PM
Hi, I would like to know how to make my target object to be non-singleton, when I also need my object transactional?

for example,

I have my Service object with following setting in application config

<object id="CategoryService" type="XYZ.Service.CategoryService, XYZ">
<property name="CategoryDao" ref="CategoryDao"/>
</object>

<object id="CategoryDao" type="XYZ.Persistence.CategoryDao, XYZ">
<property name="SessionFactory" ref="SessionFactory"/>
</object>

<object id="TxProxyConfigurationTemplate" abstract="true" type="Spring.Transaction.Interceptor.TransactionProxyFac toryObject, Spring.Data">
<property name="PlatformTransactionManager" ref="HibernateTransactionManager"/>
<property name="TransactionAttributes">
<name-values>
<add key="*" value="PROPAGATION_REQUIRED"/>
</name-values>
</property>
</object>

<object id="CategoryServiceProxy" parent="TxProxyConfigurationTemplate">
<property name="Target" ref="CategoryService"/>
</object>


When I want to get transactional object of CategoryService, I need to get CategoryServiceProxy from application context, and CategoryServiceProxy object is singleton. I need non-singleton, which is ebery time when I get CategoryService from context, I need new instance. I don't know how to do that. I try to set CategoryService object with singleton="false" but it's not work.

Does anybody colud help on this issue?
many thanks!

Bruno Baia
08-13-2007, 12:39 PM
Hi,

it's not really intuitive, but to proxy prototype, you have to use PrototypeTargetSource (http://www.springframework.net/docs/1.1-RC1/reference/html/aop.html#aop-ts-prototype) (by default, SingletonTargetSource is used).
don't forget to mark your target object as singleton="false.


<object id="CategoryService" type="XYZ.Service.CategoryService, XYZ" singleton="false">
<property name="CategoryDao" ref="CategoryDao"/>
</object>

<object id="CategoryDao" type="XYZ.Persistence.CategoryDao, XYZ">
<property name="SessionFactory" ref="SessionFactory"/>
</object>

<object id="TxProxyConfigurationTemplate" abstract="true" type="Spring.Transaction.Interceptor.TransactionProxyFac toryObject, Spring.Data">
<property name="PlatformTransactionManager" ref="HibernateTransactionManager"/>
<property name="TransactionAttributes">
<name-values>
<add key="*" value="PROPAGATION_REQUIRED"/>
</name-values>
</property>
</object>

<object id="CategoryServiceProxy" parent="TxProxyConfigurationTemplate">
<property name="Target">
<object id="prototypeTargetSource" type="Spring.Aop.Target.PrototypeTargetSource, Spring.Aop">
<property name="targetObjectName" value="CategoryService" />
</object>
</property>
</object>


HTH,
Bruno

floyd
08-13-2007, 05:08 PM
Hi Bruno,

Thanks for your reply and I try to read document after I posted and make some configurations in my App.config. And finally looks like the other post of mine http://forum.springframework.net/showpost.php?p=8407&postcount=3. Did I misuse the configurations? And after configuration setting done the other problem is describe in that post.

please help on that.
many thanks and you guys are really nice on helping people!