4 Replies Latest reply on Mar 20, 2002 9:03 PM by lasterra

    Auto numbers / DB Sequence in EJB

    porkkodi

      I have a problem with Sequence numbers in EJB. Assume that my table has auto generated sequence as Primary Key. When I am creating a bean, I could not give the value for that field in my bean. It will be got from the DB after inserting the record. How to manage this situation ? Will my EJBean(CMP) insert the record without primary key field ? Any code samples ?

        • 1. Peace of cake.
          ko5tik

          What about creation of "SequeneEJB", which will generate
          those numbers for you.

          They are indexed using bean names, and every bean having
          need in sequence number could call up this sequene EJB for a new ID

          Alternative would be to specify some environment variable in DD for a bean in question.

          I also wrote some utility clases which perform necessary lookup and makes programming really easy ( basically
          calling static method on utility class )

          • 2. Re: Peace of cake.
            roysun

            What is SequeneEJB?

            Roy

            • 3. Re: Peace of cake.
              alice_adler01

              I guess what Konstantin means is that u can create an EJB (session) that u can name as equenceEJB. This bean will have a method getId() that will actually talk to the DB to get a sequence number (from a pre-defined DB sequence).

              • 4. Re: Peace of cake.
                lasterra

                there is a good code example in theserverside.com

                http://www.theserverside.com/books/EJBDesignPatterns/index.jsp

                I Think that you have to be registered to download the code, but it's free.

                Good Luck, Enrique