Results 1 to 4 of 4

Thread: Problem with PROPAGATION_REQUIRES_NEW

  1. #1
    Join Date
    Jul 2007
    Posts
    2

    Default 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. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    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

  3. #3
    Join Date
    Jul 2007
    Posts
    2

    Default

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

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Quote 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 at 10:32 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •