PDA

View Full Version : TransactionProxyFactoryBean with non-Spring supplied target?



calvin
Aug 25th, 2004, 08:53 PM
I would like to use the declarative transaction management abililities of TransactionProxyFactoryBean in conjunction with JTATransactionManager and JOTM.

My problem is that I can't wire-up the target on TransactionProxyFactoryBean, because the object that is to be proxied is supplied by Hibernate (recreated from database), and so isn't defined in my applicationContext.xml configuration file. As I understand it, the tx proxy factory bean only proxies the object that it is wired to in the configuration file.

I tried manually getting the factory bean and setting the target programmatically, but there was a startup error saying that target was not set.

This is what I have in my applicationContext.xml file so far:


<bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBea n"/>
<bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransaction Manager">
<property name="userTransaction">
<ref local="jotm"/>
</property>
</bean>
<bean id="xaDataSource" class="org.enhydra.jdbc.standard.StandardXADataSource"
singleton="false" destroy-method="shutdown">
<property name="transactionManager">
<ref local="jotm"/>
</property>
</bean>
<bean id="xaPoolDataSource"
class="org.enhydra.jdbc.pool.StandardXAPoolDataSource"
destroy-method="shutdown" singleton="false">
<property name="dataSource">
<ref local="xaDataSource"/>
</property>
</bean>
<bean id="jtaTransactionProxy"
class="org.springframework.transaction.interceptor.Transa ctionProxyFactoryBean" lazy-init="true">
<property name="transactionManager">
<ref local="jtaTransactionManager"/>
</property>
<property name="transactionAttributes">
<props>
<!-- write actions&#58; rollback if any exception occurs -->
<prop key="execute*">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
<property name="target">
<bean id="quartzJob" class="com.thatone.archie.engine.job.QuartzJobImpl" singleton="false"/>
</property>
</bean>

Any help or pointers to resources that might be helpful would be really appreciated.

thanks...

Rod Johnson
Aug 26th, 2004, 03:45 AM
I'm not sure it's good usage, but you could define a transactional prototype bean and configure Hibernate to get a prototype instance from the current application context instance of using new when creating a new object. I can't remember the details of how to do this with Hibernate, but I know some users do use DI on Hibernate-managed instances this way.

There will be a performance overhead compared to using new, but you should be OK unless you're retrieving large numbers of objects.

rmangi
Aug 30th, 2004, 01:36 PM
I'm not sure it's good usage, but you could define a transactional prototype bean and configure Hibernate to get a prototype instance from the current application context instance of using new when creating a new object. I can't remember the details of how to do this with Hibernate, but I know some users do use DI on Hibernate-managed instances this way.

There will be a performance overhead compared to using new, but you should be OK unless you're retrieving large numbers of objects.

Any more leads on where to do this? We're facing a similar issue. Is this transactional prototype bean something we would create based on a Hibernate class or a Spring class?