Announcement Announcement Module
Collapse
No announcement yet.
TransactionProxyFactoryBean with non-Spring supplied target? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • TransactionProxyFactoryBean with non-Spring supplied target?

    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:

    Code:
    <bean id="jotm" class="org.springframework.transaction.jta.JotmFactoryBean"/>
    <bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
    	<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.TransactionProxyFactoryBean" 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...

  • #2
    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.

    Comment


    • #3
      Originally posted by Rod Johnson
      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?

      Comment

      Working...
      X