Discussions

EJB design: how to define compund primary key in home interface

  1. hello everybody,

    1) can anybody tellme how to give the compond primary key in the findByPrimaryKey method.

    if first id userid and second is password when i give
    findByPrimaryKey(java.lang.String , java.lang.String ) it is gicing error in ejbc.
    please help me.

    2) we are not getting how to deploy the entity bean using cmp in weblogic 5.1.0
    the error we get is:
    Compiler failed executable.exec([Ljava.lang.String;[C:/jdk1.2.2/bin/javac.exe, -classpath, C:\weblogic\myserver\serverclasses;C:\weblogic\jre1_2\lib\tools.jar;C:\weblogic\jre1_2\jre\lib\rt.jar;C:\weblogic\jre1_2\jre\lib\i18n.jar;C:\weblogic\license;C:\weblogic\classes\boot;C:\weblogic\classes;C:\weblogic\lib\weblogicaux.jar;C:\weblogic\eval\cloudscape\lib\cloudscape.jar;C:\weblogic\license;C:\weblogic\classes;C:\weblogic\myserver\serverclasses;C:\weblogic\lib\weblogicaux.jar;C:\weblogic\lib\persistence\WebLogic_RDBMS.jar;C:\WINDOWS\.ejbdeployer\provider-projects\HelloRec10\ejb-jar;;C:\WINDOWS\.ejbdeployer\provider-projects\HelloRec10\ejb-jar;;C:\WINDOWS\.ejbdeployer\provider-projects\HelloRec10\ejb-jar, -d, C:\WINDOWS\.ejbdeployer\provider-projects\HelloRec10\ejb-jar, C:\WINDOWS\.ejbdeployer\provider-projects\HelloRec10\ejb-jar\Bank\CheckingsBeanHomeImpl.java, C:\WINDOWS\.ejbdeployer\provider-projects\HelloRec10\ejb-jar\Bank\CheckingsBeanEOImpl.java, C:\WINDOWS\.ejbdeployer\provider-projects\HelloRec10\ejb-jar\Bank\CheckingsPS.java])

    the error in console is cannot cast Primarykeyclass to primaitive datatype.

    please someone help me.

    with regards
    k.ramakrishna
    (kalavendi at yahoo dot com)
  2. Compound primary keys , do they exist? In a table u can have only one primary key right. Home Interface will it support ? It wont.
    Am i right?
    Padmanabh
  3. Provide a wrapper class for your PK:

    eg:

    public class BeanPK implements Serializable {

    public String pkField1;
    public String pkField2;

    public int hashCode() {
                   ...
            }

            public boolean equals(Object rhs) {
                    ...
                    
            }
    }
  4. Hi,
    Thats right for different tables and anyone of these primary key variables should be activated.
    U should have overloaded constructors in PK class n each should invoke either of these variables(PK) based on ur needs.
    Padmanabh
  5. Primary Key Class:

    When deploying an entity bean, we have to specify a primary key for that. This key could be of any type belonging to a java.lang.String or any other java class. In most cases, your primary key class will be a String or some other class that belongs to the java package.

    Creating a Primary Key Class:

    For some entity beans, you will need to define your own primary key class. For example, if a primary key is composed of multiple fields then you must create a primary key class. In the following primary key class, the productId and vendorId fields together uniquely identify an entity bean:

        public class ItemKey implements java.io.Serializable {
           
           public String productId;
           public String vendorId;

           public ItemKey() { };

           public ItemKey(String productId, String vendorId) {
             this.productId = productId;
             this.vendorId = vendorId;
           }
         
           public String getProductId() {
              return productId;
           }


          public String getVendorId() {
              return vendorId;
           }
         
           
           public boolean equals(Object other) {
              if (other instanceof ItemKey) {
                 return (productId.equals(((ItemKey)
                         other).productId)
                         && vendorId.equals(((ItemKey)
                                            other).vendorId));
              }

              return false;
           }

           public int hashCode() {
              return productId.hashCode();
           }

        }


    Class Requirements:

    A primary key class must meet these requirements:

    - The access control modifier of the class is public.
    - All fields are declared as public.
    - For container-managed persistence, the field names in the primary key class must match the corresponding container-managed fields in the entity bean class.
    - The class has a public default constructor.
    - The class implements the hashCode() and equals(Object other) methods.
    - The class is serializable.

    ===============
    thanks...hasan
    (ahamed at aztec dot soft dot net)