4 Replies Latest reply on Aug 12, 2004 8:16 AM by aloubyansky

    Transaction RequiresNew Problem

    wisper2002

      Hi,

      I'm using JBoss 3.2.1 with Hibernate 2.1 and a DB2 local-tx-datasource (driver file: db2jcc.jar). There is one methodA with transaction attribute "Required" calling another methodB with attribute "RequiresNew". Normally I would assume when methodA is rolled back, changes made in methodB are not affected. But this is not the case. All changes made in methodA and methodB get rolled back.

      Why does this happen? Does anybody know about this issue?

      best regards


      To illustrate things, a method call hierarchy in pseudo code:

      [Required]
      methodA() {
      
       // Read/write business data.
      
       [RequiresNew]
       methodB() {
       // Write log messages.
       // Should not be affected by a rollback in methodA.
       // But it is.
       }
      
       // Rollback methodA.
       getSessionContext().setRollbackOnly();
      }



        • 1. Re: Transaction RequiresNew Problem
          wisper2002

          I forgot to mention:

          methodB is called over getSessionContext().getEJBObject() ofcourse.

          • 2. Re: Transaction RequiresNew Problem
            aloubyansky

            Works for me with Oracle9i and 3.2.6rc2.

             /**
             * @ejb.interface-method
             * @ejb.transaction type="RequiresNew"
             */
             public void run(long l) throws Exception
             {
             final long startTime = System.currentTimeMillis();
             log.debug("RUN>");
            
             AUtil.getLocalHome().create(new Long(1), "avoka");
             ((Facade)ctx.getEJBObject()).run2();
            
             ctx.setRollbackOnly();
            
             log.debug("RUN> done in " + (System.currentTimeMillis() - startTime) + " ms.");
             }
            
             /**
             * @ejb.interface-method
             * @ejb.transaction type="RequiresNew"
             */
             public void run2() throws Exception
             {
             final long startTime = System.currentTimeMillis();
             log.debug("RUN2>");
            
             AUtil.getLocalHome().create(new Long(2), "ataka");
            
             log.debug("RUN2> done in " + (System.currentTimeMillis() - startTime) + " ms.");
             }
            


            The db contains only row with id 2.

            • 3. Re: Transaction RequiresNew Problem
              aloubyansky

              It seems like an issue with Hibernate. Please post on the Hibernate forums.

              • 4. Re: Transaction RequiresNew Problem
                aloubyansky

                Is the session object shared between the transactions?