Announcement Announcement Module
Collapse
No announcement yet.
Problem using TransactionProxyFactoryBean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem using TransactionProxyFactoryBean

    I have the follwing code:

    Code:
    <bean id="txTemplateProxy" abstract="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    	<property name="transactionManager"><ref bean="transactionManager"/></property>
    	<property name="transactionAttributes">
    		<props>
    			<prop key="insert*">PROPAGATION_NOT_SUPPORTED</prop>
    			<prop key="_insert*">PROPAGATION_REQUIRED</prop>
    		</props>
    	</property>
    </bean>
    
    <bean id="userService" parent="txTemplateProxy">
    	<property name="target">
    		<bean class="eg.UserServiceImpl"></bean>
    	</property>
    </bean>
    Code:
    public class UserServiceImpl implements UserService &#123;
    	public void insert&#40;&#41; &#123;
    		this._insert&#40;&#41;;
    		// some business logic...
    	&#125;
    
    	public void _insert&#40;&#41; &#123;
    		// some business logic...
    	&#125;
    &#125;
    My question is when I called the _insert() method from insert(), it's not in 'PROPAGATION_REQUIRED' transaction, but PROPAGATION_NOT_SUPPORTED.
    When I call it like this "context.getBean("userService")._insert();" instead of "this._insert()", it's called as 'PROPAGATION_REQUIRED'.

    What I want to do is when I called this._insert() method from same instance, I want to run other transaction without calling like "context.getBean("userService")._insert();".

    sorry my bad english.

  • #2
    I want to run other transaction without calling like "context.getBean("userService")._insert();"
    I don't think there's any non-intrusive way to do this (except try Spring's ApectJ integration). As you know, you've got to go through the proxy for the transaction advice to get applied.

    Comment


    • #3
      As katentim said you have to use a proxy which means you need to get the bean from the Spring context. We had the same problem and tried to create several instances so bean A had a reference back to itself but in the form of A1 - however this prove to not be very scalable.
      You can refactor your code so the methods are in different beans which means calling a different method will spawn cross proxies.

      Comment


      • #4
        thank you for help.

        after that, I have found same issues that another guy got, too.
        http://forum.springframework.com/viewtopic.php?t=412
        http://forum.springframework.com/viewtopic.php?t=2174

        latter topic has a helpful solution for this problem.

        Comment

        Working...
        X