3 Replies Latest reply on May 11, 2002 9:28 PM by Stephen Coy

    Problem with null values when using a composite primary key

    Ron Jawanda Novice

      JBOSS 3.


      I am sure nobody will look at all this but I do get values from the database because I print them out in my primary key class


      as follows: but I get nulls back in my getXXX methods of the details class.
      Yeah... I know this is too much to ask.

      Wondered if there are any bugs with using Primary Key classes (i have 4 keys in my table , String, Integer, Integer, Date)

      Hope someone has the problem so I can stop working on it.




      14:54:05,397 INFO [EJBDeployer] Deploying tisfc952_Bean
      14:54:06,303 INFO [MainDeployer] Deploying: file:/C:/data/swi/jboss/deploy/jbos
      smq-state.xml
      14:54:06,366 INFO [MainDeployer] Started
      14:54:06,366 INFO [Server] JBoss (MX MicroKernel) [3.0.0beta Date:200202210220
      ] Started in 0m:23s:656ms
      14:54:36,428 INFO [Default] cprj [100 ] item [111 ] pdno[5] ocmp
      [1]
      14:54:36,460 INFO [Default] cprj [101 ] item [222 ] pdno[6] ocmp
      [1]
      14:54:36,460 INFO [Default] cprj [101 ] item [222 ] pdno[6] ocmp
      [1]
      14:54:36,460 INFO [Default] cprj [101 ] item [222 ] pdno[6] ocmp
      [1]
      14:54:36,460 INFO [Default] cprj [101 ] item [222 ] pdno[6] ocmp
      [1]
      14:54:36,460 INFO [Default] cprj [101 ] item [222 ] pdno[6] ocmp
      [1]
      14:54:36,460 INFO [Default] cprj [101 ] item [222 ] pdno[6] ocmp
      [1]
      14:54:36,475 INFO [Default] cprj [100 ] item [111 ] pdno[5] ocmp
      [1]
      14:54:36,475 INFO [Default] DETAIL IS null
      14:54:36,475 INFO [Default] Setting project!!!null
      14:54:36,475 INFO [Default] cprj [100 ] item [111 ] pdno[5] ocmp
      [1]
      14:54:36,491 INFO [Default] cprj [100 ] item [111 ] pdno[5] ocmp
      [1]
      14:54:36,491 INFO [Default] cprj [100 ] item [111 ] pdno[5] ocmp
      [1]
      14:54:36,491 INFO [Default] cprj [100 ] item [111 ] pdno[5] ocmp
      [1]
      14:54:36,522 INFO [Default] cprj [100 ] item [111 ] pdno[5] ocmp
      [1]




      I get null values that are read of of the database.

      here is what I have
      My Bean Class

      package ca.husky.baandpkg;

      import javax.ejb.EntityBean;
      import javax.ejb.EntityContext;
      import java.lang.Double ;
      import java.lang.Integer ;
      import java.sql.Date ;



      /**
      * Entity Bean representing a Class. A Class have a Teacher and a number of
      * Students
      */

      public abstract class tisfc952_Bean implements EntityBean
      {
      EntityContext ctx;

      public String cprj;
      public String item;
      public Integer pdno;
      public Integer ocmp ;

      public String revi ;
      public Double qana ;
      public Date indt ;
      public Integer clos ;
      public Integer refcntd ;
      public Integer refcntu ;

      public HighLevelItemsPK pk ;


      private tisfc952_Detail tisfc952_detail;

      /**
      * Create an instance of a Class.
      */
      public HighLevelItemsPK ejbCreate (tisfc952_Detail tisfc952_detail)
      {
      this.cprj = tisfc952_detail.getCprj() ;
      this.item = tisfc952_detail.getItem() ;
      this.pdno = tisfc952_detail.getPdno() ;
      this.ocmp = tisfc952_detail.getOcmp() ;


      setDetail(tisfc952_detail);
      return null;
      }

      public void ejbPostCreate(tisfc952_Detail tisfc952_detail) { }




      public void setDetail(tisfc952_Detail tisfc952_detail)
      {
      System.out.println("set Detail called" + tisfc952_detail ) ;


      this.cprj = tisfc952_detail.getCprj() ;
      this.item = tisfc952_detail.getItem() ;
      this.pdno = tisfc952_detail.getPdno() ;
      this.ocmp = tisfc952_detail.getOcmp() ;
      this.revi = tisfc952_detail.getRevi() ;
      this.qana = tisfc952_detail.getQana() ;
      this.indt = tisfc952_detail.getIndt() ;
      this.clos = tisfc952_detail.getClos() ;
      this.refcntd = tisfc952_detail.getRefcntd() ;
      this.refcntu = tisfc952_detail.getRefcntu() ;
      }


      public tisfc952_Detail getDetail()
      {
      System.out.println("DETAIL IS " + tisfc952_detail ) ;

      if (tisfc952_detail == null)
      {
      tisfc952_detail = new tisfc952_Detail();


      tisfc952_detail.setCprj(cprj);
      tisfc952_detail.setItem(item);
      tisfc952_detail.setRevi(revi);

      tisfc952_detail.setPdno( pdno) ;
      tisfc952_detail.setOcmp( ocmp) ;
      tisfc952_detail.setQana(qana);
      tisfc952_detail.setIndt(indt);
      tisfc952_detail.setClos(clos);

      tisfc952_detail.setRefcntd(refcntd);
      tisfc952_detail.setRefcntu(refcntu);

      }
      return tisfc952_detail ;
      }

      /*

      public void setCprj( String cprj ) {
      this.cprj = cprj ;
      }
      public void setItem( String item ) {
      this.item = item ;
      }

      public void setPdno( Integer pdno ) {
      this.pdno = pdno ;
      }
      public void setOcmp( Integer ocmp ) {
      this.ocmp = ocmp ;
      }
      public void setQana( Double qana ) {
      this.qana = qana ;
      }
      public void setIndt( Date indt ) {
      this.indt = indt ;
      }
      public void setClos( Integer clos ) {
      this.clos = clos ;
      }
      public void setRefcntd( Integer refcntd ) {
      this.refcntd = refcntd ;
      }
      public void setRefcntu( Integer refcntu ) {
      this.refcntu = refcntu ;
      }
      */


      public abstract void setCprj( String cprj ) ;

      public abstract void setItem( String item ) ;
      public abstract void setPdno( Integer pdno ) ;
      public abstract void setOcmp( Integer ocmp ) ;
      public abstract void setRevi( String revi) ;
      public abstract void setQana( Double qana ) ;
      public abstract void setIndt( Date indt ) ;
      public abstract void setClos( Integer clos ) ;
      public abstract void setRefcntd( Integer refcntd) ;
      public abstract void setRefcntu( Integer refcntu ) ;

      public abstract String getCprj( ) ;
      public abstract String getItem( ) ;
      public abstract Integer getPdno() ;
      public abstract Integer getOcmp() ;
      public abstract String getRevi() ;
      public abstract Double getQana( ) ;
      public abstract Date getIndt() ;
      public abstract Integer getClos( ) ;
      public abstract Integer getRefcntd() ;
      public abstract Integer getRefcntu( ) ;





      public void setEntityContext(EntityContext ctx) { this.ctx = ctx; }

      public void unsetEntityContext() { ctx = null; }

      public void ejbActivate() {}

      public void ejbPassivate()
      {
      tisfc952_detail = null;
      }

      public void ejbLoad()
      {
      tisfc952_detail = null;
      }

      public void ejbStore() { }
      public void ejbRemove() { }

      }

      My Primary Key Class

      package ca.husky.baandpkg ;
      import java.io.Serializable ;

      public class HighLevelItemsPK implements java.io.Serializable {
      public String cprj ;
      public String item ;
      public Integer pdno ;
      public Integer ocmp ;


      public HighLevelItemsPK() {
      }
      public HighLevelItemsPK(String cprj, String item, Integer pdno, Integer ocmp) {
      this.cprj = cprj ;
      this.item = item ;
      this.pdno = pdno ;
      this.ocmp = ocmp ;

      }

      public int hashCode() {
      return ( cprj.hashCode() + item.hashCode() + pdno.hashCode() + ocmp.hashCode() ) ;
      }
      public boolean equals(Object pObject) {
      System.out.println(" cprj [" + cprj + "] item [" + item + "] pdno[" + pdno + "] ocmp ["+ ocmp + "]") ;
      return( ((HighLevelItemsPK)pObject).cprj.equals(cprj) &&
      ((HighLevelItemsPK)pObject).item.equals(item) &&
      ((HighLevelItemsPK)pObject).pdno.equals(pdno) &&
      ((HighLevelItemsPK)pObject).ocmp.equals(ocmp) ) ;

      /* if (pObject == null || !(pObject instanceof HighLevelItemsPK))
      return false;
      else if ( this.cprj.equalsIgnoreCase(((HighLevelItemsPK)pObject).cprj) &&
      this.item.equalsIgnoreCase(((HighLevelItemsPK)pObject).item) &&
      this.ocmp.compareTo( ( (HighLevelItemsPK)pObject).ocmp) == 0 &&
      this.pdno.compareTo( ( (HighLevelItemsPK)pObject).pdno) == 0 ) {
      System.out.println("TRUE") ;
      return true;
      } else {
      System.out.println("FALSE") ;

      return false;
      }*/

      }

      public String toString() {
      StringBuffer sb = new StringBuffer();
      sb.append(cprj);
      sb.append(item);
      sb.append(pdno);
      sb.append(ocmp);
      return (sb.toString());
      }

      }

      The detail class which

      package ca.husky.baandpkg ;

      import java.io.Serializable;

      import java.sql.Date ;


      public class tisfc952_Detail
      implements Serializable
      {

      private String cprj;
      private String item;
      private Integer pdno;
      private Integer ocmp ;

      private String revi ;
      private Double qana ;
      private Date indt ;
      private Integer clos ;
      private Integer refcntd ;
      private Integer refcntu ;



      public String getCprj() {
      return cprj;
      }

      public void setCprj(String cprj) {
      System.out.println("Setting project!!!" + cprj ) ;

      this.cprj = cprj;
      }

      public String getItem() {
      return item;
      }
      public void setItem(String item) {
      this.item = item;
      }

      public void setPdno(Integer pdno) {
      this.pdno = pdno;
      }
      public Integer getPdno() {
      return pdno ;
      }
      public void setOcmp(Integer ocmp) {
      this.ocmp = ocmp;
      }
      public Integer getOcmp() {
      return ocmp ;
      }

      public void setRevi(String revi) {
      this.revi = revi;
      }
      public String getRevi() {
      return revi ;
      }

      public void setQana(Double qana) {
      this.qana = qana;
      }
      public Double getQana() {
      return qana ;
      }

      public void setIndt(Date indt) {
      this.indt = indt;
      }
      public Date getIndt() {
      return indt ;
      }
      public void setClos(Integer clos) {
      this.clos = clos;
      }
      public Integer getClos() {
      return clos ;
      }

      public void setRefcntd(Integer refcntd) {
      this.refcntd = refcntd;
      }
      public Integer getRefcntd() {
      return refcntd ;
      }
      public void setRefcntu(Integer refcntu) {
      this.refcntu = refcntu;
      }
      public Integer getRefcntu() {
      return refcntu ;
      }



      }


      Home



      package ca.husky.baandpkg;

      import javax.ejb.EJBHome;

      import javax.ejb.CreateException;
      import javax.ejb.FinderException;
      import java.rmi.RemoteException;
      import java.util.Collection;

      public interface tisfc952_Home extends EJBHome
      {
      public tisfc952_Home create(tisfc952_Detail tisfc952_detail)
      throws CreateException, RemoteException;

      public Collection findAll()
      throws FinderException, RemoteException;

      public Collection findByPrimaryKey (HighLevelItemsPK pk)
      throws RemoteException, FinderException;

      }

      package ca.husky.baandpkg;

      import javax.ejb.EJBLocalObject;

      public interface tisfc952_Local extends EJBLocalObject
      {
      public tisfc952_Detail getDetail();

      public void setDetail(tisfc952_Detail tisfc952_detail) ;

      }

      package ca.husky.baandpkg;

      import javax.ejb.EJBObject;
      import java.rmi.RemoteException;

      public interface tisfc952_Remote extends EJBObject
      {
      public tisfc952_Detail getDetail() throws RemoteException;

      public void setDetail(tisfc952_Detail tisfc952_detail) throws RemoteException;

      }

      XML FILE

      <jbosscmp-jdbc>
      <enterprise-beans>

      <ejb-name>tisfc952_Bean</ejb-name>
      <table-name>ttisfc952001</table-name>
      java:/OracleDS
      <type-mapping>Oracle8</type-mapping>
      <create-table>false</create-table>
      <remove-table>false</remove-table>
      true


      <cmp-field>
      <field-name>cprj</field-name>
      <column-name>T$CPRJ</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>item</field-name>
      <column-name>T$ITEM</column-name>
      <!-- <jdbc-type>VARCHAR</jdbc-type> -->
      <!-- <sql-type>VARCHAR(50)</sql-type> -->

      </cmp-field>
      <cmp-field>
      <field-name>pdno</field-name>
      cd etc
      <column-name>T$PDNO</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>revi</field-name>
      <column-name>T$REVI</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>revi</field-name>
      <column-name>T$REVI</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>ocmp</field-name>
      <column-name>T$OCMP</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>qana</field-name>
      <column-name>T$QANA</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>indt</field-name>
      <column-name>T$INDT</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>clos</field-name>
      <column-name>T$CLOS</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>refcntd</field-name>
      <column-name>T$REFCNTD</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>refcntu</field-name>
      <column-name>T$REFCNTU</column-name>
      </cmp-field>

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