2 Replies Latest reply on Jun 4, 2003 2:33 PM by hqic

    non-null object results in 'null-object' lock exception

    hqic

      All,

      I have this code snippet:

      ===================================
      aCustomer = (CustomerLocal)aCustomerLocalHome.create("lastName","firstName","addressLine1");
      if (aCustomer == null)
      return;

      System.out.println("name : " + aCustomer.getFirstName() + " " + aCustomer.getLastName());
      ===================================

      When I execute this code, the entity bean does get created (at least a row is inserted in the db as expected). I get passed the 'if null' check, but on the Sytem.out.println() line I get the following error:

      org.jboss.tm.JBossTransactionRolledbackException: Attempt to get lock ref with a null object; CausedByException is:
      Attempt to get lock ref with a null object; nested exception is:
      java.lang.IllegalArgumentException: Attempt to get lock ref with a null object; - nested throwable: (java.lang.IllegalArgumentException: Attempt to get lock ref with a null object)
      at org.jboss.ejb.plugins.LogInterceptor.handleException(LogInterceptor.java:262)
      at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:195)
      at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
      ...

      This is a bit perplexing since I have a non-null object and the database was, indeed, updated. Any help would be appreciated.

      Mike.

        • 1. Re: non-null object results in 'null-object' lock exception

          You haven't mapped your primary key correctly,
          you are probably using an auto-increment
          in the db. You need to tell jboss this.

          Use search in the CMP forum.

          Regards,
          Adrian

          • 2. Re: non-null object results in 'null-object' lock exception
            hqic

            Adrian,

            Thanks for setting me on the right track... you were exactly right, I was using MySQL's auto-increment on the primary key field and that was confusing JBoss. Here is the solution. I modified jbosscmp-jdbc.xml for the entity bean in question as follows:

            <jbosscmp-jdbc>
            <enterprise-beans>

            ...
            <!-- added the following to handle auto-incement pk -->
            <unknown-pk>
            <unknown-pk-class>java.lang.Integer</unknown-pk-class>
            <field-name>id</field-name>
            <column-name>id</column-name>
            <jdbc-type>INTEGER</jdbc-type>
            <sql-type>INT(11)</sql-type>
            <auto-increment/>
            </unknown-pk>
            <entity-command name="mysql-get-generated-keys"/>
            <!-- end of handling auto-increment pk -->
            ...

            </enterprise-beans>
            </jbosscmp-jdbc>

            There is a more complete discusson of this at:

            http://www.kylev.com/projects/jboss/cmpauto.html

            Mike.