1 Reply Latest reply on Oct 2, 2002 2:41 PM by Alexey Loubyansky

    Oracle sequences and PKs

    Mark LaPolla Newbie

      If I want to create a PK, in oracle, I can use a sequence to create the next PK for me. How do I map an e bean or in some other way access that sequence so that I can have a unique PK each time.

      I could use a table an map an e bean to it but that's not as nice as using Oracle sequences.

      Basically, what I am asking, is on insert, where do you come up with the appropriate PK? Do you have a finder that looks for the largest PK in a table and adds one?

      I'd rather use an Oracle sequence but I cannot seem to access them at all.

      Thanks again.

        • 1. Re: Oracle sequences and PKs
          Alexey Loubyansky Master

          It's possible using unknow primary key.

          In ejb-jar.xml prim-key-class must be java.lang.Object and no primkey-field.

          ejbCreate method must return java.lang.Object and findByPrimaryKey must take the parameter of type java.lang.Object.

          In jbosscmp-jdbc.xml you should place something like this:
          <!-- pk-sql generated unknown-pk; overriding default sql -->

          ...
          <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 is supported in Branch_3_2.