1 Reply Latest reply on Sep 4, 2002 11:58 AM by Dain Sundstrom

    Remote Exception when using Composite Primary Key

    Damian Sutton Newbie

      Hi All,

      I have noticed that most people with Composite Primary Key Problems have trouble getting them to work. I don't seem to have a problem creating, doploying or using Composite Primary Keys on JBoss 3.0.1 / Tomcat 4.0.4 .

      But I have found that when using remote methods on the bean that has a Composite Primary Key, a Remote Exception is thrown.

      I can use the home.findByPrimaryKey(myKey) method successfully, I print the bean that is returned (I works). But if I call any get or set methods it brakes.

      Here some of my code that might help.

      (in the ejb-jar.xml)

      Models the TxCarcass Table
      <ejb-name>TxCarcassBean</ejb-name>
      pig.TxCarcassHome
      pig.TxCarcass
      <ejb-class>pig.TxCarcassBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>pig.TxCarcassKey</prim-key-class>
      False
      <cmp-field>
      <field-name>site</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>deviceAddr</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>devicePort</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>txDate</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>txTime</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>txSeq</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>txChain</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>txStation</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>txType</field-name>
      </cmp-field>


      (primary key class)
      public class TxCarcassKey implements java.io.Serializable {
      public String site;
      public String deviceAddr;
      public String devicePort;
      public Date txDate;
      public Integer txSeq;

      /** Creates a new instance of TxCarcassKey */
      public TxCarcassKey() { }

      public boolean equals(Object obj) {
      if(obj == null) {
      return false;
      }
      if(obj instanceof TxCarcassKey) {
      if(((TxCarcassKey)obj).hashCode() ==
      this.hashCode()) {
      return true;
      }
      }
      return false;
      }

      public int hashCode() {
      return this.toString().hashCode();
      }

      public String toString() {
      return site + "|" + deviceAddr + "|" + devicePort + "|" + txDate.toString() + "|" + txSeq.toString();
      }
      }

      (implementation bean create method)
      public TxCarcassKey ejbCreate(String site, String deviceAddr, String devicePort, Date txDate, Integer txSeq) {
      this.site = site;
      this.deviceAddr = deviceAddr;
      this.devicePort = devicePort;
      this.txDate = txDate;
      this.txSeq = txSeq;
      return null;
      }

      (home class)
      public interface TxCarcassHome extends javax.ejb.EJBHome {
      public TxCarcass create(String site, String
      deviceAddr, String devicePort, Date txDate, Integer txSeq) throws RemoteException, CreateException;

      public TxCarcass findByPrimaryKey(TxCarcassKey key)throws RemoteException, FinderException;

      public java.util.Collection findAll() throws RemoteException, FinderException;
      }

      (test client)
      public static void main(String[] args) {
      try {
      System.out.println("Hello");
      SimpleDateFormat sf = new SimpleDateFormat ("dd/MM/yyyy");
      InitialContext namingContext = new InitialContext();
      TxCarcassHome home = (TxCarcassHome) PortableRemoteObject.narrow(namingContext.lookup ("TxCarcassBean"), TxCarcassHome.class);
      TxCarcassKey key = new TxCarcassKey();
      key.site = "TEST SITE 2";
      key.deviceAddr = "A";
      key.devicePort = "1";
      key.txDate = sf.parse("29/08/2002");
      key.txSeq = new Integer(0);
      TxCarcass bean = home.findByPrimaryKey(key);
      System.out.println(bean);
      System.out.println(bean.getSite());
      } catch (Exception z) {
      z.printStackTrace();
      }
      }

      (output from test)

      Hello
      TxCarcassBean:TEST SITE 2|A|1|Thu Aug 29 00:00:00 EST 2002|0
      java.rmi.ServerException: RemoteException occurred in server thread; nested exce
      ption is:
      java.rmi.ServerException: Load failed; nested exception is:
      java.lang.NullPointerException
      at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:292)
      at sun.rmi.transport.Transport$1.run(Transport.java:148)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
      at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:4
      60)
      at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport
      .java:701)
      at java.lang.Thread.run(Thread.java:536)
      at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Stream
      RemoteCall.java:247)
      at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:
      223)

      ....and lots more


      Sorry about how long this has been, but please can someone help me out.

      Cheers