1 Reply Latest reply on Jul 9, 2003 8:13 AM by thl-mot

    Null pointer of reading field

    edross

      When trying to read a field that has a null in the database I get the following error

      05:44:02,206 ERROR [LogInterceptor] TransactionRolledbackLocalException, causedBy:
      java.lang.NullPointerException
      at techrx.ejb.PatientCMP$Proxy.getSourcePharmacyId()
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.jboss.ejb.EntityContainer$ContainerInterceptor.invoke(EntityContainer.java:1044)


      The field is defined as an int
      (in this case pharmacyId in null) which explicitly allows nulls. If there is a value in the field, all is well, if there is a null in the field then error. I seem to get this on all fields that have nulls in them.

      Using sybase (but the same problem appears when I use mySql)

      The bean has the follwing:

      /**
      * Returns the sourcePharmacyId
      * @todo support OracleClob,OracleBlob on WLS
      *
      * @return the sourcePharmacyId
      *
      * @ejb.interface-method view-type="local"
      * @ejb.persistent-field
      * @ejb.persistence column-name="source_pharmacy_id"
      */
      public abstract int getSourcePharmacyId();

      /**
      * Sets the sourcePharmacyId
      *
      * @param sourcePharmacyId the new sourcePharmacyId value
      * @ejb.interface-method view-type="local"
      */
      public abstract void setSourcePharmacyId(int sourcePharmacyId);

      (as you might detect - using xdoclet to gen the code)

      the generated ejb-jar.xml has

      <cmp-field >
      <![CDATA[Returns the sourcePharmacyId]]>
      <field-name>sourcePharmacyId</field-name>
      </cmp-field>

      the jbosscmp-jdbc.xml has:

      <cmp-field>
      <field-name>sourcePharmacyId</field-name>
      <column-name>source_pharmacy_id</column-name>

      </cmp-field>


      The same problem exists with all fields that have nulls.

      I can not regenerate the database as there are millions of rows (well, on the test system 1000's, but still need the data for testing)


      I'm rather new to jboss, so hope this is a simple question.

        • 1. Re: Null pointer of reading field
          thl-mot

          That seams to be very simple.

          You just can not use datatypes that do not allow null values on db columns that allow nulls. How do you want to be the null represented as an int, double or boolean?

          You have to use java.lang.Integer, java.lang.Double, ...