Announcement Announcement Module
Collapse
No announcement yet.
@Transactional method : transaction not propagated : individual commits Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @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
    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

    Comment


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

      Comment


      • #4
        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).

        Comment


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

          Comment

          Working...
          X