3 Replies Latest reply on Oct 1, 2002 12:40 PM by mmazur

    CMP and Obtaining nextval from an Oracle Sequence

    mmazur

      Is there a way to have the container return the nexval of an Oracle Sequence besides writing jdbc code????

      The primary key of my Oracle table is an Integer which is linked to an Oracle sequence. I have done a work-around by writing some jdbc code within my bean class's ejbCreate method to get the sequence.nextval, then returning that value.

      in doing the workaroound, i seem to have created a mix of BMP/CMP. there must be a way for the container to return the nextval.

      I also tried to write an ejbSelect method, but when you write the ejb-jar.xml query, how do you write the EJB-QL select statement??? the abstract schema name refers to the Oracle Table not the SequenceName.

      help

        • 1. Re: CMP and Obtaining nextval from an Oracle Sequence
          aloubyansky

          You can do it using unknown primary key. That is a key of type java.lang.Object.
          The declaration of entity in jbosscmp-jdbc.xml should look like this:

          <ejb-name>MyBean</ejb-name>

          <!--
          | specify unknown primary key and sql to fetch next
          | value
          -->
          <unknown-pk>
          <unknown-pk-class>java.lang.Integer</unknown-pk-class>
          <column-name>genid</column-name>
          <jdbc-type>INTEGER</jdbc-type>
          <sql-type>INTEGER</sql-type>
          </unknown-pk>
          <entity-command name="pk-sql">
          SELECT SEQ_2279_1.nextval FROM DUAL
          </entity-command>


          This will work only in Branch_3_2 and HEAD.

          • 2. Re: CMP and Obtaining nextval from an Oracle Sequence
            mmazur

            thank you.

            next question . . .

            the container will get the nexval, how do I retrive the value in my ejbCreate method of the bean class???? where is this value sitting after the container retrieves it?????

            • 3. Re: CMP and Obtaining nextval from an Oracle Sequence
              mmazur

              where is this nextval sitting after the container retrives it???? how do i access it in my ejbCreate method of my bean class?????

              thanx again