3 Replies Latest reply on Jun 18, 2004 3:49 AM by u9707118

    EJB not committing

    u9707118 Newbie

      OK, let me first say that I am really new to JBOSS - so I'm probably doing something really stupid...

      In my code, I have a loop that creates a series of EJB's.
      In order to find a unique id, I use an sql statement to find the highest value primary key (say 6) and I increment by one (7).

      This works for creating the first EJB in the loop - however, on the 2nd iteration of the loop, the sql statement returns a high primary key of 6 (again - as if the first ejb created is not reflected in the database). However, when I increment this value to 7 and try to create the next EJB, a DuplicateKeyException is thrown.

      What is going on?
      How can I commit data to the database when the EJB is created?



        • 1. Re: EJB not committing
          gorano Newbie

          I don't know what your implementation looks like
          , but I think you have to very
          careful with the approach you have taken.

          Create a separate UniqueID table instead, that keep track of the Ids.


          • 2. Re: EJB not committing
            u9707118 Newbie

            Hi, thanks for the reply.

            The reason I am confused is because when using Oracle 9i Application Server...when you create an EJB (supplying a unique ID), this is reflected immediately in the database.

            However in JBOSS, (as described in the above scenario), this is not true.


            • 3. Re: EJB not committing
              u9707118 Newbie

              I have solved my problem!
              In case anyone has the same problem... it is to do with ejb-transactions.

              I had to set the ejb transaction for my particular ejb to RequiresNew so that the transaction is commited immediately.