Ooops,  Thanks Stanislas.

Don't for get the hashCode and equals methods in the primary key
classes........

-----Original Message-----
From: Stanislas Truffaut
Sent: 20 December 2000 17:11
To: Tim Squires
Subject: RE: compound key


Hi,

be carefull a PK class as said in ejb specification must implement
hashCode() and equals() method....



----------------------------------------------------------------------------
----

From: Tim Squires
Subject: RE: compound key
Date: Wed, 20 Dec 2000 04:21:46 -0800

----------------------------------------------------------------------------
----

What you need to do is create a primary key class with the primary keys in
it:

--------------------

public class answerPK implements java.io.Serializable
{

  public Integer Id;
  public Integer Answer_Type_Id;
  /**
   * Constructor
   */
  public answerPK( Integer Id, Integer Answer_Type_Id )
  {
    this.Id = Id;
    this.Answer_Type_Id = Answer_Type_Id;
  }

  public answerPK() {}

  public Integer getId() throws java.rmi.RemoteException
  {
    return Id;
  }

  public void setId( Integer Id ) throws java.rmi.RemoteException
  {
    this.Id = Id;
  }

  public Integer getAnswer_Type_Id()
    throws java.rmi.RemoteException
  {
    return Answer_Type_Id;
  }

  public void setAnswer_Type_Id( Integer Answer_Type_Id )
    throws java.rmi.RemoteException
  {
    this.Answer_Type_Id = Answer_Type_Id;
  }

}

--------------------------------------------------------

You can then specify in your descriptor:
<prim-key-class>answerPK</prim-key-class>

You still put the variables into your bean class and return the primary key
class ( e.g. answerPK ) from the ejbCreate.

  public answerPK ejbCreate( Integer Id, Integer Answer_Type_Id )
    throws CreateException, RemoteException
  {
    this.Id = Id;
    this.Answer_Type_Id = Answer_Type_Id;
    return new answerPK( Id, Answer_Type_Id );
  }

Have fun,
Tim.



-----Original Message-----
From: Henry Hu [mailto:[EMAIL PROTECTED]]
Sent: 16 December 2000 02:21
To: Orion-Interest
Subject: compound key


Could anybody tell me how I can specify a compound key in the descriptor
file? When the primary key consists of  2 or more fields, the DTD told
me not to specify the  "<primkey-field></primkey-field> "tag.  However,
the deployment has an error as

   No direct database fields for primary key

Please help.

Henry



Reply via email to