Error while deploying CMP entity beans on weblogic 5.1..HELP!!

Discussions

EJB programming & troubleshooting: Error while deploying CMP entity beans on weblogic 5.1..HELP!!

  1. I am unable to solve the error prompted to me by BEA weblogic 5.1 server for EJB1.1. Here is the code ...
    <pre>

    Primary Key Class - ShipPK.java
    -------------------------------
    import java.io.Serializable;

    public class ShipPK implements java.io.Serializable {

    public int id;

    public ShipPK(){}
    public ShipPK(int value){
    id = value;
    }
    public int hashCode(){
    return id;
    }

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

    public String toString(){
    return String.valueOf(id);
    }
    }

    Home Interface - ShipHome.java
    ------------------------------
    import javax.ejb.EJBHome;
    import javax.ejb.CreateException;
    import javax.ejb.FinderException;
    import java.rmi.RemoteException;
    import java.util.Enumeration;

    public interface ShipHome extends javax.ejb.EJBHome {

    public Ship create(int id, String name, int capacity)
    throws RemoteException,CreateException;
    public Ship create(int id, String name)
    throws RemoteException,CreateException;
    public Ship findByPrimaryKey(ShipPK primaryKey)
    throws FinderException, RemoteException;
    }

    Remote Interface - Ship.java
    ----------------------------
    import javax.ejb.EJBObject;
    import java.rmi.RemoteException;

    public interface Ship extends javax.ejb.EJBObject {
    public String getName() throws RemoteException;
    public void setName(String name) throws RemoteException;
    public void setCapacity(int cap) throws RemoteException;
    public int getCapacity() throws RemoteException;
    }

    EntityBean - ShipBean.java
    --------------------------
    import javax.ejb.EntityContext;

    public class ShipBean implements javax.ejb.EntityBean {
    public int id;
    public String name;
    public int capacity;

    private EntityContext context;

    public ShipPK ejbCreate(int id, String name, int capacity){
    this.id = id;
    this.name = name;
    this.capacity = capacity;
    return null;
    }
    public void ejbPostCreate(int id, String name, int capacity){
    ShipPK pk = (ShipPK)context.getPrimaryKey();
    }
    public ShipPK ejbCreate(int id, String name){
    this.id = id;
    this.name = name;
    capacity = 0;
    return null;
    }
    public void ejbPostCreate(int id, String name){
    Ship myself = (Ship)context.getEJBObject();
    }
    public void setEntityContext(EntityContext ctx){
    context = ctx;
    }
    public void unsetEntityContext(){
    context = null;
    }
    public void ejbActivate(){ }
    public void ejbPassivate(){ }
    public void ejbLoad(){ }
    public void ejbStore(){ }
    public void ejbRemove(){ }

    public String getName(){
    return name;
    }
    public void setName(String n){
    name = n;
    }
    public void setCapacity(int cap){
    capacity = cap;
    }
    public int getCapacity(){
    return capacity;
    }
    }

    </PRE>
    I am able to compile sucessfully all the above .java files....but while deploying them I am getting the error

    Error Message:
    --------------
    C:\WINDOWS\.ejbdeployer\provider-projects\shipcmp\ejb- jar\ShipBeanEOImpl.java:56: Incompatible type for =. Can't convert int to ShipPK.

    pk = bean.id;

    ^

    C:\WINDOWS\.ejbdeployer\provider-projects\shipcmp\ejb- jar\ShipBeanEOImpl.java:109: Incompatible type for =. Can't convert int to ShipPK.

    pk = bean.id;

    ^
    I am unable to find the problem...as I am new to EJB this is the error I am encountering with other examples also. This is only for CMP. Can any one please help me out. I'll be grateful. Thanx,
    Krtrao.

  2. try the weblogic newsgroups at
    news://newsgroups.bea.com

    Filip
  3. The problem is that before generating container while filling up the persistence attributes, u are probably giving primary key field also. Leave it as (none). When you are already giving primary key type then you don't have to give primary key field.

    Sumit
  4. what Sumit has said abouve is correct , also the attribute id in ur ShipPK is of type int , change it to Integer , else u may get more problems
  5. Even we have faced the same problem. finally we changed int (primitive) to Integer and we did not had any primary key class. The ejbcreate method returns Integer in method signature and return null inside the method. specify java.lang.Integer for primarykey tag in rdbms-xml file. change int to Integer in all the places. and you need not parse Integer to int in ejbcreate or any where else as the container takes care . this holds good for all primitive types as primary key.