Hi, I am trying to use CMP for entity bean for a simple database table having three columns, namely, cust_id(int), item_code(varchar2), quantity(int). While I am genetrating the Jar file, I am getting the incompatible ERROR. I could not understand where exactly the error is: My code is as under: Please help me out. Smitha ================================================================= REMOTE INTERFACE <---------------> package ejb.entityBean.containerManaged.testing; import java.sql.*; import java.rmi.RemoteException; public interface Order extends javax.ejb.EJBObject { public void setQuantity(int quantity) throws RemoteException; public int getCustID() throws RemoteException; public String getItemCode() throws RemoteException; public int getQuantity() throws RemoteException; } _________________________________________________________________ HOME INTERFACE <-------------> package ejb.entityBean.containerManaged.testing; import java.rmi.RemoteException; import java.sql.*; import java.util.Collection; import javax.ejb.*;
public interface OrderHome extends EJBHome { public Order create(int custid, String itemcode, int quantity) throws RemoteException, CreateException; public Order findByPrimaryKey(OrderPK pk) throws FinderException, RemoteException; } _________________________________________________________________ PRIMARY KEY CLASS <---------------> package ejb.entityBean.containerManaged.testing; import java.sql.*; public class OrderPK implements java.io.Serializable { public int custid; public OrderPK() { } public OrderPK(int custid) { this.custid = custid;; } public boolean equals(Object obj) { if (obj==null | | !(obj instanceof OrderPK)) return false; OrderPK pk = (OrderPK)obj; if (this.custid != pk.custid) return false; return true; } public int hashCode() { StringBuffer strB = new StringBuffer(); strB.append(custid); return strB.toString().hashCode(); } public String toString() { String b = "OrderPK[custid=" + custid ; return b; } } _________________________________________________________________ BEAN CLASS <---------> package ejb.entityBean.containerManaged.testing; import java.rmi.*; import javax.ejb.*; import java.sql.*; public class OrderBean implements EntityBean { private boolean isModified = false; public EntityContext entityContext; public int custid; public String itemcode; public int quantity;
public OrderPK ejbCreate(int cust_id, String item_code, int quant) throws CreateException {
Hi Smitha, First of all if you are setting Cust_id as primary key class then you can't use the getCustid()method.Use instead getPrimaryKey() method.This is std method for getting the primary key of an entity bean.Also check with Hashcode for int.I feel it gives problem sometimes.Also the method EJBCreate in bean should return Primary key class,(return(new(orderPK(custid))) should be written instead of return null. Just try this if any problem let me know. Thanx, Mahesh
smitharai
Greenhorn
Joined: Aug 20, 2001
Posts: 4
posted
0
Hi Mahesh, Thanks for the reply. There is no compile ERROR when I changed the return type for the ejbCreate() method to "return new OrderPK(custid);". But when I tried to generate the JAR file, I am getting the ERROR like "Error in OrderBeanEOImpl.java:56: incompatible types found : int required: ejb.entityBean.containerManaged.testing.OrderPK, pk = bean.custid; I could not understand this. Please correct my mistake. Thanks, Smitha
Marcela Blei
Ranch Hand
Joined: Jun 28, 2000
Posts: 477
posted
0
"smitharai": Your name is not valid as per the Javaranch name conventions. Please refer to the document located here: http://www.javaranch.com/name.jsp
ranga 786
Greenhorn
Joined: Aug 28, 2001
Posts: 4
posted
0
Better use SimplePrimary key Instead of compound primarykey class I.e dont create primary key class and use wrapper class it will solve ur purpose
I can't see the problem, but it looks like one I often had. It's really telling you the truth in the error message, though. One thing you might do is check your deployment to make sure that you have specified that the primary key is given as a CLASS rather than a FIELD (since it's possible to put data in both places a lot of people do this wrong). You may also want to set the keepgenerated option on the ejbc step and actually look at the code being compiled. The message hints at it, though. Normally "pk" would be an OrderPK and bean.custid would be an int, so pk = bean.custid SHOULD give a type mismatch!
Customer surveys are for companies who didn't pay proper attention to begin with.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.