3 Replies Latest reply on Dec 9, 2002 12:08 PM by pcollet

    cannot create an entity bean followed by a getPrimaryKey()

    pcollet

      All,

      I have been trying to create an entity bean from a session bean and right after get its primary key. It always throws an IllegalArgumentException when accessing the primary key. If I just create the entity bean then everything works just fine. Any idea? I'm stuck right now and I would appreciate any pointers/help.

      I'm running JBoss 3.0.4 with MySQL.

      [...]
      MyEntityBean eb = MyEntityBean.create(title, age);
      System.out.println("created "+eb.getPrimaryKey());
      [...]


      17:34:23,645 DEBUG [Study] Create: pk=null

      17:34:23,661 DEBUG [Study] Executing SQL: SELECT COUNT(*) FROM study WHERE uid=?

      17:34:23,661 DEBUG [Study] Executing SQL: INSERT INTO study (uid, protocol, title, public_access, study_design_uid) VALUES (?, ?, ?, ?, ?)

      17:34:23,661 DEBUG [Study] Rows affected = 1

      17:34:23,723 ERROR [LogInterceptor] TransactionRolledbackLocalException, causedBy:

      java.lang.IllegalArgumentException: Attempt to remove a lock for a null object

      at org.jboss.ejb.BeanLockManager.removeLockRef(BeanLockManager.java:103)

      at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:124)

      at org.jboss.ejb.plugins.EntityCreationInterceptor.invoke(EntityCreationInterceptor.java:69)

      at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:107)

      at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:178)

      at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:60)

      at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:130)

      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:204)

      at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:493)

      at org.jboss.ejb.plugins.local.BaseLocalContainerInvoker.invoke(BaseLocalContainerInvoker.java:301)

      at org.jboss.ejb.plugins.local.EntityProxy.invoke(EntityProxy.java:38)

      at $Proxy79.getPrimaryKey(Unknown Source)

        • 1. Re: cannot create an entity bean followed by a getPrimaryKey
          joelvogt

          which field have you defined as your pk? Have you made sure this isn't null before the create?

          • 2. Re: cannot create an entity bean followed by a getPrimaryKey
            pcollet

            Hi,

            I'm using an auto-generated key on the table (called uid) so I believe I don't need to specify a value in the ejbCreate() method. Is that right?

            Thanks for your help,
            Pascal

            • 3. Re: cannot create an entity bean followed by a getPrimaryKey
              pcollet

              I turned on the debug flag and here is the SQL code that is executed before the rollback error:

              11:10:28,525 DEBUG [MbtPoms] Create: pk=null
              11:10:28,525 DEBUG [MbtPoms] Executing SQL: SELECT COUNT(*) FROM mbt_poms WHERE uid=?
              11:10:28,525 DEBUG [MbtPoms] Executing SQL: INSERT INTO mbt_poms (uid, created, start, stop, subject_uid, visit_uid) VALUES (?, ?, ?, ?, ?, ?)
              11:10:28,541 DEBUG [MbtPoms] Rows affected = 1
              11:10:28,541 ERROR [LogInterceptor] TransactionRolledbackLocalException, causedBy:
              java.lang.IllegalArgumentException: Attempt to remove a lock for a null object
              at org.jboss.ejb.BeanLockManager.removeLockRef(BeanLockManager.java:103)
              at org.jboss.ejb.plugins.EntityLockInterceptor.invoke(EntityLockInterceptor.java:124)


              the rest of the execution stack is the same than shown in previous message.