Discussions

EJB programming & troubleshooting: Please check my code

  1. Please check my code (4 messages)

    hi everyone,

    I have written these interfaces and classes. i am deploying my application using wl deployer tool. i have included the home interface, remote interface , primarykey class and the bean interface in the deployer tool. i am selecting the persistance for all the three fields viz name,id,salary.
    when i am trying to deploy it gives a error saying
    "n EJB Employee, the home interface must define the findByPrimaryKey method."
    thanx a lot.....................

    here is my code
    ---------------------
    Home interface :::
    ---------------------------------------------------------
    package examples.ejb.basic.containerManaged;

    import java.rmi.*;
    import javax.ejb.*;

    public interface EmployeeHome extends EJBHome
    {
    Employee create(String id,String name,float salary) throws RemoteException,CreateException;
       public Employee findByPrimaryKey(EmployeePK pk) throws RemoteException,FinderException;
    }
    ------------------------------------------------------------Remote interface
    ----------------------------------------------------------

    package examples.ejb.basic.containerManaged;

    import java.rmi.*;
    import javax.ejb.*;

    public interface Employee extends EJBObject
    {
    float getSalary() throws RemoteException;
    void setSalary(float f) throws RemoteException;
    }
    ------------------------------------------------------------
    beanclass
    -----------------------------------------------------------
    package examples.ejb.basic.containerManaged;

    import java.rmi.*;
    import javax.ejb.*;

    public class EmployeeBean implements EntityBean
    {
    public String id;
    public String name;
    public float salary;
    private EntityContext ec;

    public void ejbActivate() {}
    public void ejbPassivate() {}
    public void ejbRemove() {}
    public void ejbLoad(){}
    public void ejbStore(){}

    public void setEntityContext(EntityContext ec)
    {
    this.ec = ec;
    }
    public void unsetEntityContext()
    {
    this.ec = null;
    }

    public String ejbCreate(String id,String name,float salary)
    {
    this.id = id;
    this.name = name;
    this.salary = salary;
    return null;
    }
    public void ejbPostCreate(String id,String name,float salary)
    {
    }

    public float getSalary()
    {
    return this.salary;
    }
    public void setSalary(float f)
    {
    this.salary = f;
    }

    public boolean isModified()
    {
    return true;
    }
    }
    ------------------------------------------------------------primarykey class
    ----------------------------------------------------------
    package examples.ejb.basic.containerManaged;

    import java.io.Serializable;

    public class EmployeePK implements java.io.Serializable
    {
    public String Employeeid;

    public EmployeePK(String Employeeid)
    {
    this.Employeeid = Employeeid;
    }

    public EmployeePK()
    {
    }

    public String toString()
    {
    return Employeeid.toString();
    }

    }
    ------------------------------------------------------------

    Threaded Messages (4)

  2. change yr code[ Go to top ]

    Change yr EmployeePK.java

    replace public string EmployeeId to public string id;

    Rinku

  3. change yr code[ Go to top ]

    hi,

    i have changed it, it does not work....

    can i do it without a primary key class............

    thanks
  4. change yr code[ Go to top ]

    Hi Mahadevan,

    Please make the following changes in u'r code:

    In the EmployeeBean make the ejbCreate method to return PrimaryKey.

    Code u'r PrimaryKey as follows:

    public class EmployeePK implements java.io.Serializable
    {
    public String id;


       //public int id;

        public int hashCode( )
        {
            return Integer.parseInt(id);
        }

        public boolean equals(Object obj)
        {
            if(obj instanceof EmployeePK)
            {
                return (id == ((EmployeePK)obj).id);
            }
            return false;
        }

    }

    Hope this will do..

    Regards
    Saran
  5. change yr code[ Go to top ]

    hi saran,

    thanks a lot, how come i forgot the concept of hashcode...

    will mail you tomorrow after trying out your code........

    thanks again......

    good night.....(it is around 8:30 at germany)

    bye
    madhavan