Results 1 to 5 of 5

Thread: @Transactional method : transaction not propagated : individual commits

  1. #1
    Join Date
    Mar 2009
    Posts
    14

    Default @Transactional method : transaction not propagated : individual commits

    Using Spring 3 + hibernate3 + c3p0 and hibernate transaction manager.
    In the below I expect the data to be deleted and then inserted in one atomic transaction. The issue is that another process reading the data (using C2 method readAll) between the delete and insert times sees no data.

    Code:
    ===============
    class C1 { <= C1 is injected into Main : this is a Java Application
     private C2 c2;  <= injected
    
    @Transactional(value="myTransactionManager", isolation= Isolation.SERIALIZABLE, propagation= Propagation.REQUIRES_NEW)
      private m1(List l) {
          c2.deleteAll();
          c2.insertList(l);
      }
    }
    
    ===============
    
    @Transactional(value="myTransactionManager", isolation= Isolation.SERIALIZABLE, propagation= Propagation.REQUIRED)
    class C2 {
      // has a DAO that uses C3P0 connection pool to mysql
      // method deleteAll()...
      // method insertList()...
      // method readAll()...
    }

  2. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    Hello

    isolation= Isolation.SERIALIZABLE
    Has sense, well done

    Just an observation, you are using in Class C1
    Code:
    propagation= Propagation.REQUIRES_NEW
    I think it should be
    Code:
    propagation= Propagation.REQUIRED
    like Class C2 too

    Just try it

    Let me know your advance
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3
    Join Date
    Mar 2009
    Posts
    14

    Default

    Thank you for the compliment.
    I do think I need Propagation.REQUIRES_NEW because each call to the first method in C1 should be its own isolated transaction. I imaging that the existing one is suspended? since they are not nested? Propagation.REQUIRED will allow this multiple calls to join the existing transaction which is setup on the first calls (assuming something like recursive calls)
    ==
    The issue is that C2 methods call DAO methods (none of which are annotated and there is no AOP used for transactions in the beans.xml) Each call to the DAO method would seem to be in its own transaction instead of part of the new transaction setup in the C1 method call.

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    You use MySQL make sure you use transactional tables. Also make sure you use the transaction manager which fits your technology (hibernate -> HibernateTransactionManager, plain jdbc DataSourceTransactionManager etc.). Also make sure your @Transactional actually does something (make sure you have tx:annotation-driven).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Mar 2009
    Posts
    14

    Default

    Since the ORM is Hibernate - using HibernateTransactionManager
    Since this is spring3 - using specific Transactional(value="myTransactionManager") and the methods on C1 and C2 both use the same named bean. The transaction annotations are being found/used since replacing "HibernateTransactionManager" with "HibernateTransactionManager_" in the code does result in a runtime error. How should tx:annotation-driven be used with multiple transaction manager named beans? I have one set of these tags for each defined manager.

Tags for this Thread

Posting Permissions

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