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.
Discussions
EJB programming & troubleshooting: Error while deploying CMP entity beans on weblogic 5.1..HELP!!
-
Error while deploying CMP entity beans on weblogic 5.1..HELP!! (4 messages)
- Posted by: Trivikram Rao
- Posted on: October 24 2000 21:05 EDT
Threaded Messages (4)
- Error while deploying CMP entity beans on weblogic 5.1..HELP!! by Filip Hanik on October 24 2000 21:16 EDT
- Error while deploying CMP entity beans on weblogic 5.1..HELP!! by sumit gupta on October 25 2000 10:25 EDT
- Error while deploying CMP entity beans on weblogic 5.1..HELP!! by Somil Nanda on October 25 2000 15:24 EDT
- Error while deploying CMP entity beans on weblogic 5.1..HELP!! by Web Master on October 31 2000 04:43 EST
-
Error while deploying CMP entity beans on weblogic 5.1..HELP!![ Go to top ]
- Posted by: Filip Hanik
- Posted on: October 24 2000 21:16 EDT
- in response to Trivikram Rao
try the weblogic newsgroups at
news://newsgroups.bea.com
Filip -
Error while deploying CMP entity beans on weblogic 5.1..HELP!![ Go to top ]
- Posted by: sumit gupta
- Posted on: October 25 2000 10:25 EDT
- in response to Trivikram Rao
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 -
Error while deploying CMP entity beans on weblogic 5.1..HELP!![ Go to top ]
- Posted by: Somil Nanda
- Posted on: October 25 2000 15:24 EDT
- in response to sumit gupta
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 -
Error while deploying CMP entity beans on weblogic 5.1..HELP!![ Go to top ]
- Posted by: Web Master
- Posted on: October 31 2000 04:43 EST
- in response to Trivikram Rao
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.