1 2 Previous Next 16 Replies Latest reply on Sep 23, 2010 2:33 PM by pablo.fraga1975

    Can't get @TransactionTimeout to work

    rlj

      I have a Stateless EJB3 bean which specify:

      @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
      @TransactionTimeout(3600)
      public Long doMerge(String someParams) {
       // Some DB acces which runs for more than 5 minutes
       // which is the default transaction-timeout value
      }
      


      I'm deploying this on the JBossAS v. 4.0.5-GA

      But it dos'nt seem to work. I get a transaction timeout after the default value of 5 minutes.

      If I use the "fix" given here:
      http://www.jboss.com/index.html?module=bb&op=viewtopic&t=108173
      I do get two timeout messages follow each-other

      I've spent two days crawling the net looking for documentation on how to use this annotation. If someone could tell me exactly how this should be working I would be very glad.

      /RLJ


        • 1. Re: Can't get @TransactionTimeout to work

          I'm facing the same problem. Did anyone managed to solve the problem?

          Thx,
          Mihai

          • 2. Re: Can't get @TransactionTimeout to work
            jaikiran

            2 year old post and an old version of JBoss.

            Please explain your issue in more detail. Which version of JBoss AS and Java do you use? What does your code look like? What exact issue do you see?

            • 3. Re: Can't get @TransactionTimeout to work

              My objective is to set a different timeout (greater than default of 5 mins) for a method that need to process a group of objects in a long transaction. So I tried to use the @TransactionTimeout annotation. Below is a simplified pseudocode with what I want to do.

              @PersistenceContext
              EntityManager em;
              
              @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
              @TransactionTimeout(3600)
              public Long doLongTransaction(List<BaseEntity> entities)
              {
               for(BaseEntity entity : entities)
               {
               if (condition)
               persistEntity(entity);
               else
               updateEntity(entity);
               }
              }
              @TransactionAttribute(TransactionAttributeType.REQUIRED)
              public void persistEntity(BaseEntity entity)
              {
               em.persist(entity);
              }
              @TransactionAttribute(TransactionAttributeType.REQUIRED)
              public void updateEntity(BaseEntity entity)
              {
               em.merge(entity);
              }
              


              If I try to set a minimum timeout to see if the transaction for this method will timeout let's say, after a minute it doesn't work, it will only timeout after the default 5 minutes value.
              Am I missing something. Is there any other possibility to set a different transaction timeout for a method without affecting the global transaction default timeout?

              Thanks,
              Mihai

              • 4. Re: Can't get @TransactionTimeout to work
                jaikiran

                Which version of JBoss AS? And please post the import statement that you have (especially for the Transaction* annotations)

                • 5. Re: Can't get @TransactionTimeout to work

                  Jboss version used is 4.0.5 GA with ejb3 deployer, 'all' configuration. The import statement are like in the code below.

                  import org.jboss.annotation.ejb.TransactionTimeout;
                  import javax.ejb.*;
                  
                  @PersistenceContext
                  EntityManager em;
                  
                  @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
                  @TransactionTimeout(3600)
                  public Long doLongTransaction(List<BaseEntity> entities)
                  {
                   for(BaseEntity entity : entities)
                   {
                   if (condition)
                   persistEntity(entity);
                   else
                   updateEntity(entity);
                   }
                  }
                  @TransactionAttribute(TransactionAttributeType.REQUIRED)
                  public void persistEntity(BaseEntity entity)
                  {
                   em.persist(entity);
                  }
                  @TransactionAttribute(TransactionAttributeType.REQUIRED)
                  public void updateEntity(BaseEntity entity)
                  {
                   em.merge(entity);
                  }
                  


                  Thanks,
                  Mihai

                  • 6. Re: Can't get @TransactionTimeout to work

                    Can this problem occur from the fact that I'm using the @TransactionTimeout annotation from org.jboss.* package, and the others from javax.ejb.*? Did anyone faced this problem?

                    Thx,
                    Mihai

                    • 7. Re: Can't get @TransactionTimeout to work
                      jaikiran

                      Can you try upgrading to later versions of JBoss (like 4.2.3 GA or 5.1.0 GA) and try this. 4.0.5 GA by default did not have EJB3 support and required EJB3 patches to be applied.

                      • 8. Re: Can't get @TransactionTimeout to work
                        richardvanduijn

                        I'm experiencing the same problem. I'm currently using JBoss 5.1.0 GA and still the transaction timeout is set to the default value.

                        I've read in other posts that you require a new transaction in order to allow the timeout Annotation to work. So I've done this, with little success.

                        Any ideas anyone?
                        Thanks in advance
                        Richard

                        • 9. Re: Can't get @TransactionTimeout to work
                          jaikiran

                           

                          "richardvanduijn" wrote:
                          I'm experiencing the same problem. I'm currently using JBoss 5.1.0 GA and still the transaction timeout is set to the default value.


                          Without looking at your code, i guess you are importing the wrong packages for the transaction timeout annotation. You should be using:

                          @org.jboss.ejb3.annotation.TransactionTimeout




                          • 10. Re: Can't get @TransactionTimeout to work
                            richardvanduijn

                            You're correct that I'm not correclty importing the annotation.
                            I'm using org.jboss.annotation.ejb.TransactionTimeout

                            Which jar provides me with this class?
                            Thanks for your quick response.

                            Regards,
                            Richard

                            • 11. Re: Can't get @TransactionTimeout to work
                              richardvanduijn

                              Ah found the jar its called:\jboss-ejb3-ext-api.jar
                              My maven project did not update correctly somehow, not updating the ejb package name to ejb3.
                              Will see if it works now. Again, thank you for your reply.

                              • 12. Re: Can't get @TransactionTimeout to work
                                richardvanduijn

                                Ah nice, solution works.

                                • 13. Re: Can't get @TransactionTimeout to work
                                  pablo.fraga1975

                                  Hi,

                                  I have the same problem. I'am using EJB3, JBoss 4.2.3 GA, SLSB with CMP transactions.

                                  Code snap:

                                  import org.jboss.annotation.ejb.TransactionTimeout;

                                  @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
                                  @TransactionTimeout(15)
                                  public AbstractResult compra(AbstractCommand command){

                                  The timeout doesn't work for me using this annotation with this full qualified name.

                                  But the thing is that i can't find the other one in any jar provided by JBoss. Can't find org.jboss.ejb3.annotation.TransactionTimeout.

                                  Any help?

                                  Pablo.



                                  • 14. Re: Can't get @TransactionTimeout to work
                                    pablo.fraga1975

                                    I forgot to mention that if I change the transaction management type to BEAN it does work.

                                    @TransactionManagement(TransactionManagementType.BEAN)

                                    But I don't want to change the default transaction type, and what is more, I didn't find anywhere in the documentation of JBoss that this is needed to work it out, any suggestions?

                                    Pablo.

                                    1 2 Previous Next