Announcement Announcement Module
Collapse
No announcement yet.
How to make transactions span multiple DAO-ops? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to make transactions span multiple DAO-ops?

    Hi!

    This is a question about DAOs, business objects and how to make their (i.e the business objects) transaction-safe.

    One of the Spring distribution samples contains a LogicFacade backed up by a LogicFacadeImpl which is regarded as the primary (and only) business object. Transactions works well, no problems there, and I'm even beginning to understand some of the mechanisms behind it.

    However, I've been searching for information regarding the use of BOs from a transactional point of view. My idea is to limit the number of methods in the DAO, maybe CRUDs only and to make the DAO member of a BO, and then invoking its DAO member. One reason for this is mr Johnson's advice in his "J2EE Dev. wo EJB" to avoid large "God objects" like for example LogicFacade.

    My question is; is it possible to make a construct like
    Code:
    public Object invoke(Object command){
    
    	getDao().performDBOperation();
    	//etc
    	//etc
    	getDao().performAnotherDBOperation();
    	.
    	.
    
    }
    transactional, ie if 'performAnotherDBOperation' fails, 'performDBOperation' is rolled back?

    Of course both DB-operation have their individual transaction safeness, but how do I make them work as a "team"?

    I hope my question is understandable.

    Thanks!

  • #2
    It happens automatically if the "invoke" method uses a transaction attribute like PROPAGATION_REQUIRED. Basically, if either DAO method throws an exception, the whole thing rolls back.

    Comment


    • #3
      Thanks!


      :roll:
      I'm just stupid, of course transactions must involve a TxManager of some kind...duh!

      But; can you use the same TxManager for many transactions. I understand that each business object must have its own TransactionProxyFactoryBean... is this correct?

      Comment


      • #4
        Correct. All TransactionProxyFactoryBeans can refer to the same transaction manager.

        Comment

        Working...
        X