0 Replies Latest reply on Sep 12, 2002 1:19 PM by tcorley

    Primary Key and Entity bean

    tcorley

      JBoss 3.0: CMP 2.0: Hypersonic

      Following the example of GansterBean in chapter 9 of the
      "JBoss 3.0 Getting Started Guide", I have created a PersonBean that is pretty much a cut an past of gangster with a few more data fields. My question is about the primary key.

      The gangster example explisitly sets the id upon creation. I would like to let Hypersonic self incriment the keys by defining the column in my table create statement as:
      "Person_InsId INTEGER IDENTITY,
      CONSTRAINT PersonPK PRIMARY KEY ( PERSON_INSTID )"

      First name and last name are not null columns in this table and create statement like the following works fine:


      public Integer ejbCreate( String FIRST_NAME, String LAST_NAME, Integer PERSON_INSTID ) throws CreateException, RemoteException
      {
      setFIRST_NAME(FIRST_NAME);
      setLAST_NAME(LAST_NAME);
      setPERSON_INSTID(PERSON_INSTID );
      return( null );
      }

      When I remove the inst id setting like this:


      public Integer ejbCreate( String FIRST_NAME, String LAST_NAME) throws CreateException, RemoteException
      {
      setFIRST_NAME(FIRST_NAME);
      setLAST_NAME(LAST_NAME);
      return( null );
      }

      A create call from my client results in
      1. The entry gets added to the database with the key incrimented.
      2. The MT throws "java.lang.IllegalStateException: removing bean lock and it has tx set"
      3. The client sometimes locks on the return call, sometimes it get exception passed back.



      I am pretty new to EJB, if you know what I am doing wrong any help would be appreciated.