Announcement Announcement Module
Collapse
No announcement yet.
Declarative flush as transactionAttribute??? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Declarative flush as transactionAttribute???

    Is there some feature that allows a declarative flush as a transactionAttribute similar to PROPAGATE_REQUIRED???

    i.e FLUSH_MANDATORY

    This way if I call several service methods within on transaction I can declaratively cause a flush to check for successful insert.

    i.e:

    service1: /* transaction begins */
    try {
    call service 2
    } exception {
    check for exception i.e: a db insert failed due to constraint
    }
    call service 3
    /* transaction ends */

    in this example

    service 1,2 & 3 are proxied by TransactionProxyFactoryBean
    and the transaction attributes on 2 cause flush.

    In the real example I am trying to implement there is no service 1 and the code is as follows. Service 2 & 3 are transaction proxied normally but because transaction is already started the parent transaction is used:
    Code:
    TransactionStatus transaction 
       = getTransactionManager().getTransaction(
            new DefaultTransactionDefinition());
    
    call service2
    call service 3
    
    getTransactionManager().commit(transaction);

  • #2
    There's no way right now to force a flush. As you say, if there's an existing transaciton it's just joined. Is there something stopping you from actually doing a manual flush? This is what is normally done (inside or outside spring) by code that doesn't know if it's running as part of an existing transaction or not...

    Comment


    • #3
      It would be just cleaner to do it declaratively

      It would be just cleaner to do it declaratively. Why is that facility not available? Is there some other way to approach this problem?

      Comment


      • #4
        For one thing, flushing is not a transactional aspect. How do you actually flush, in terms of an abstraction that works across all the technologies. i.e. something like HibernateTransactionManager could know how to flush hibernate sessions, but what about JDBC access on the same connection, and what about when you switch to JTATransactionManager.

        Comment


        • #5
          continued

          Well the transaction manager itself relies on transactionAttributes to decide what it supports and what it can do. In the case of JDBC the JDBCTransaction manager would simply ignore the flush attribute....

          Comment


          • #6
            It's an interesting idea. I agree with Colin that it doesn't really belong in with declarative transaction management, but you could write your own aspect that you apply as a pre or post interceptor using TransactionProxyFactoryBean, or however you drive Spring declarative transactions.

            Comment


            • #7
              Could you provide an example...

              Could you provide an example?

              Comment

              Working...
              X