1 Reply Latest reply on Jan 8, 2004 7:33 PM by dgefter

    Autogenerated PK with Oracle using unknown-pk

    dgefter Newbie

      Hi,
      I'm having a problem with ejbcreate method throwing an error saying that it cannot insert null in the pk column. The bean is:
      /**
      * @ejb.bean
      * name="mybean"
      * display-name="mybean"
      * view-type="local"
      * type="CMP"
      * schema="Periodcommandresult"
      * cmp-version="2.x"
      * primkey-field="id"
      * local-jndi-name="mybean"
      *
      * @ejb.transaction type="Required"
      *
      * @jboss.unknown-pk
      * class="java.lang.Long"
      * field-name="id"
      * column-name="id"
      * jdbc-type="INTEGER"
      * sql-type="INTEGER"
      * auto-increment="true"
      * @jboss.entity-command
      * name="pk-sql"
      * @jboss.entity-command-attribute
      * name="pk-sql"
      * value="SELECT PCM_RT_SEQ.nextval FROM DUAL"
      *
      * @jboss.persistence create-table="false"
      * remove-table="false"
      * read-only="false"
      * pk-constraint="true"
      * row-locking="false"
      **/
      abstract public class MyBean implements javax.ejb.EntityBean
      {
      /**
      * @ejb.pk-field
      * @ejb.persistent-field
      * @ejb.interface-method
      * @ejb.persistence
      * column-name="id"
      * @ejb.transaction
      * type="NotSupported"
      * @jboss.auto-increment
      */
      public abstract Long getId();
      public abstract void setId(Long newId);

      /**
      *
      * @ejb.interface-method
      * view-type="local"
      */
      public Long getGeneratedPrimaryKey()
      {
      return (Long) entityContext.getPrimaryKey();
      }

      /**
      * @ejb:create-method
      */
      public java.lang.Long ejbCreate () throws CreateException
      {
      return null;
      }
      }
      --------------------------------------------
      Could somebody offer any help please?
      Thanks a lot

        • 1. Re: Autogenerated PK with Oracle using unknown-pk
          dgefter Newbie

          I forgot to mention that we're using JBoss 3.2.1 and thin driver for Oracle 9i. Also, I see in the database log that following statements are passed in:
          1. SELECT PCM_RT_SEQ.nextval FROM DUAL
          2. SELECT COUNT(*) FROM mytable WHERE id='21'
          3. INSERT INTO mytable(id, field1) VALUES ('', '')
          and line 3 throws exception:
          java.sql.SQLException: ORA-01400: cannot insert NULL into ("mytable"."ID")

          So, it seem that the problem is that entity obtains sequence generated primary key(step 1), checks for duplication(step 2) and does not setup primary key.

          Thanks