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

  • Problem with PROPAGATION_REQUIRES_NEW

    I am new to spring and hibernate. I am running in a problem. I hope someone out there will help me!!!

    Here is the situation. I am using spring 2.0.1 and Hibernate 3.2 on Jboss 4.0.5. I have a collection of
    model objects and need to update each of them in separate transaction meaning failure of update operation on
    one object should not affect the operation on other objects in the collection. For that, I created a parent method
    that loops through the collection and calls a child method passing each of these objects which makes actual
    database call through hibernate.

    I am using following configuration.

    <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTran sactionManager">
    <property name="transactionManagerName">
    <value>java:/TransactionManager</value>
    </property>
    <property name="transactionSynchronization">
    <bean id="org.springframework.transaction.jta.JtaTransac tionManager.SYNCHRONIZATION_NEVER"
    class="org.springframework.beans.factory.config.Fi eldRetrievingFactoryBean"/>
    </property>

    </bean>

    <bean id="transactionInterceptor"
    class="org.springframework.transaction.interceptor .TransactionInterceptor">
    <property name="transactionManager">
    <ref bean="transactionManager" />
    </property>
    <property name="transactionAttributes">
    <props>
    <prop key="*">PROPAGATION_REQUIRES_NEW</prop>
    </props>
    </property>
    </bean>

    <bean
    class="org.springframework.aop.framework.autoproxy .BeanNameAutoProxyCreator">
    <property name="beanNames">
    <value>myService</value> <!-- myService bean has those methods to update the model object -->
    </property>
    <property name="interceptorNames">
    <list>
    <value>transactionInterceptor</value>
    </list>
    </property>
    </bean>

    For test purpose I am throwing RuntimeException from the child method like following.

    public void updateModel(MyModel mm ,int i){
    mmDao.update(mm); //hibernate dao
    if(i%2 == 0) // doing this just to check - trying to make one call success and next one fail
    throw new RuntimeException();

    }

    But everytime it is commiting the database change even if this child method is throwing exception. Could you please tell
    me why?

    P.S. I am catching exception in the web tier in order to show the user friendly message, so the exception does not bubble up to the opensessioninview filter.

  • #2
    If this is an inner method call then you won't proxy the object and therefore you won't get the new transaction. It would be useful to see the code so this could be confirmed. You could call into another service which means it would be in a new transaction or use TransactionTemplate instead around each item.
    http://www.springframework.org/docs/...ng-aop-proxies

    Comment


    • #3
      Thanks karldmoore!
      I used the transactiontemplate and it is working like a charm. I will try with second approach whenever I get time.

      Comment


      • #4
        Originally posted by kali_001 View Post
        I used the transactiontemplate and it is working like a charm. I will try with second approach whenever I get time.
        Not a problem! Another thing to keep an eye on is Spring Batch, this might be a nicer solution to these kind of problems in the long term.
        Last edited by karldmoore; Aug 29th, 2007, 11:32 AM.

        Comment

        Working...
        X