3 Replies Latest reply on Jul 7, 2003 10:40 AM by Adrian Brock

    Comppund key and CMP

    Jerome Godard Newbie

      hi,

      i am using JBoss 3.0.4 as EJB container. I use CMP Entity Beans to take care of the persistence into an Oracle 9.x database.

      The persistence works well for single primary keys. But I got the following message:

      "java.lang.NullPointerException
      at org.jboss.ejb.plugins.jaws.jdbc.JDBCCreateEntityCommand.execute(JDBCC
      reateEntityCommand.java:119)
      at org.jboss.ejb.plugins.jaws.JAWSPersistenceManager.createEntity(JAWSPe
      rsistenceManager.java:255)
      at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersisten
      ceManager.java:253)
      at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.crea
      teEntity(CachedConnectionInterceptor.java:270)"

      Is there any limitation to use compound primary keys for CMP EJBs?

      Thanks for any comment,

      Jerome Godard

        • 1. Re: Comppund key and CMP
          Adrian Brock Master

          No, but you'll have to show your primary key class
          and entity bean if you want some help.

          Any reason for using the JAWS persistence engine
          other than you haven't put a dtd in your ejb-jar.xml?

          Any reason for using 3.0.4 when 3.0.8 is out?

          Regards,
          Adrian

          • 2. Re: Comppund key and CMP
            Jerome Godard Newbie

            Hi,

            here is my primary key source code :

            public class RecordPrimaryKey implements java.io.Serializable
            {
            public Integer serviceId;
            public Timestamp timeStamp = null;

            public RecordPrimaryKey()
            {
            }
            /**
            *
            * @param serviceId
            */
            public RecordPrimaryKey(Integer theServiceId)
            {
            serviceId = theServiceId;
            }

            /**
            *
            * @param serviceId
            */
            public void setServiceId(Integer theServiceId)
            {
            serviceId = theServiceId;
            }

            /**
            *
            * @return
            */
            public Integer getServiceId()
            {
            return serviceId;
            }
            /**
            * Builds a human-readable version of the object
            * @return a String
            */
            public String toString()
            {
            String builtString = "Record key: " + serviceId + " - " + timeStamp;

            return builtString;
            }
            /**
            * @return
            */
            public Timestamp getTimeStamp()
            {
            return timeStamp;
            }

            /**
            * @param timestamp
            */
            public void setTimeStamp(Timestamp timestamp)
            {
            timeStamp = timestamp;
            }

            public boolean equals(Object obj)
            {
            if (obj == null || !(obj instanceof RecordPrimaryKey))
            return false;
            else if (
            ((RecordPrimaryKey) obj).getServiceId().intValue()
            == this.serviceId.intValue()
            && ((RecordPrimaryKey) obj).getTimeStamp() == this.timeStamp)
            return true;
            else
            return false;
            }

            public int hashCode()
            {
            StringBuffer strBuff = new StringBuffer();
            strBuff.append(this.serviceId);
            strBuff.append(this.timeStamp);
            String str = strBuff.toString();
            return str.hashCode();
            }
            }


            Here after the part of the jaws.xml file


            <ejb-name>Record</ejb-name>
            <table-name>RECORDED_TS_DATA</table-name>
            <create-table>false</create-table>
            <cmp-field>
            <field-name>serviceId</field-name>
            <column-name>RTD_SRVC_ID</column-name>
            <jdbc-type>INTEGER</jdbc-type>
            <sql-type>NUMBER(22)</sql-type>
            </cmp-field>
            <cmp-field>
            <field-name>spatialActivity</field-name>
            <column-name>RTD_SPATIAL_ACTIVITY</column-name>
            <jdbc-type>INTEGER</jdbc-type>
            <sql-type>NUMBER(4)</sql-type>
            </cmp-field>
            <cmp-field>
            <field-name>temporalActivity</field-name>
            <column-name>RTD_TEMPORAL_ACTIVITY</column-name>
            <jdbc-type>INTEGER</jdbc-type>
            <sql-type>NUMBER(4)</sql-type>
            </cmp-field>
            <cmp-field>
            <field-name>dataRate</field-name>
            <column-name>RTD_DATA_RATE</column-name>
            <jdbc-type>INTEGER</jdbc-type>
            <sql-type>NUMBER(4)</sql-type>
            </cmp-field>
            <cmp-field>
            <field-name>pictureQuality</field-name>
            <column-name>RTD_PICTURE_QUALITY</column-name>
            <jdbc-type>INTEGER</jdbc-type>
            <sql-type>NUMBER(4)</sql-type>
            </cmp-field>
            <cmp-field>
            <field-name>timeStamp</field-name>
            <column-name>RTD_TIMESTAMP</column-name>
            <jdbc-type>DATE</jdbc-type>
            <sql-type>DATE</sql-type>
            </cmp-field>


            And, last, the part of ejb-jar.xml file:


            <display-name>Record</display-name>
            <ejb-name>Record</ejb-name>
            com.ses_astra.dnoc_sas.server.beans.entity.RecordedTsData
            com.ses_astra.dnoc_sas.server.beans.entity.RecordedTsDataHome
            <ejb-class>com.ses_astra.dnoc_sas.server.beans.entity.RecordedTsDataBean</ejb-class>
            <persistence-type>Container</persistence-type>
            <prim-key-class>com.ses_astra.dnoc_sas.RecordPrimaryKey</prim-key-class>
            False
            <cmp-field>
            <field-name>serviceId</field-name>
            </cmp-field>
            <cmp-field>
            <field-name>spatialActivity</field-name>
            </cmp-field>
            <cmp-field>
            <field-name>temporalActivity</field-name>
            </cmp-field>
            <cmp-field>
            <field-name>dataRate</field-name>
            </cmp-field>
            <cmp-field>
            <field-name>pictureQuality</field-name>
            </cmp-field>
            <cmp-field>
            <field-name>timeStamp</field-name>
            </cmp-field>



            I'm using JBoss 3.0.4 as a major part of the app is already in prod with that version.

            Thanks for your help,

            Jerome

            • 3. Re: Comppund key and CMP
              Adrian Brock Master

              My guess is that it either a problem of the null timestamp
              or you are changing the timestamp which is not allowed.

              I also don't think you want to do == tests on timestamp.

              You should consider upgrading to the new CMP engine.
              JAWS is no longer actively maintained and has already been
              dropped from jboss4

              Regards,
              Adrian