EJB question
Edward King <[email protected]> Sat, 15 Jan 2005 10:20:26 +0800
| Newsgroups | gmane.comp.java.sun.ejb.general |
|---|---|
| Message-ID | <001801c4faa8$c7691960$1501a8c0@windows> |
I am puzzled with EJB compile,I write a EJB and a client program,
EJB are following directory:
E:\EJB\orderMgmt\OrderManagement.class
E:\EJB\orderMgmt\OrderManagementBean.class
E:\EJB\orderMgmt\OrderManagementHome.class
and client is following directory:
E:\EJB\Client.java
when I compile Client.java,it raise following errors:
E:\EJB>javac -d . Client.java
Client.java:14: inconvertible types
found : java.lang.Object
required: OrderManagementHome
(OrderManagementHome)javax.rmi.PortableRemoteObject.narrow(
^
Client.java:16: cannot resolve symbol
symbol : method create ()
location: class OrderManagementHome
OrderManagement orderManagement=home.create();
^
Client.java:17: cannot resolve symbol
symbol : method placeOrder (java.lang.String,java.lang.String,int)
location: class OrderManagement
orderManagement.placeOrder("Cedric","J2EE Server Programming",1000);
^
Client.java:18: cannot resolve symbol
symbol : method remove ()
location: class OrderManagement
orderManagement.remove();
^
4 errors
Why raise errors?
Then I put EJB into another directory,like following:
E:\EJB\orderMgmt\orderMgmt\OrderManagement.class
E:\EJB\orderMgmt\orderMgmt\OrderManagementBean.class
E:\EJB\orderMgmt\orderMgmt\OrderManagementHome.class
Then I compile Client.java again,this time compiled ok,why this time can compile success?
I found there are more two class in the directory of E:\EJB\orderMgmt,they are OrderManagement.class and OrderManagementHome.class. Why they will be created when I compile Client?
Thanks in advance.
My class are following:
//OrderManagementHome.java
package orderMgmt;
public interface OrderManagementHome extends javax.ejb.EJBHome{
OrderManagement create() throws java.rmi.RemoteException,javax.ejb.CreateException;
}
//OrderManagement.java
package orderMgmt;
public interface OrderManagement extends javax.ejb.EJBObject{
void placeOrder(String custName,String prodName,int quantity) throws java.rmi.RemoteException;
void cancelOrder(String custName,String prodName) throws java.rmi.RemoteException;
boolean isShipped(String custName,String prodName) throws java.rmi.RemoteException;
}
//OrderManagementBean.java
package orderMgmt;
import javax.ejb.SessionContext;
public class OrderManagementBean implements javax.ejb.SessionBean{
public void placeOrder(String custName,String prodName,int quantity){
System.out.println("Order placed for "+quantity+" copies of "+prodName+" to be shipped to "+custName);
}
public void cancelOrder(String custName,String prodName){
System.out.println("Order cancelled");
}
public boolean isShipped(String custName,String prodName){
System.out.println("Order shipped");
return true;
}
public void ejbCreate(){
System.out.println("ejbCreate() called");
}
public void ejbRemove(){
System.out.println("ejbRemove() called");
}
public void ejbActivate(){
System.out.println("ejbActivate() called");
}
public void ejbPassivate(){
System.out.println("ejbPassivate() called");
}
public void setSessionContext(SessionContext ctx){
System.out.println("setSessionContext() called");
}
}
//Client.java
import orderMgmt.*;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
public class Client{
public static void main(String args[]){
try{
Properties prop=new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi;WLInitialContextFactory");
prop.put(Context.PROVIDER_URL,"t3://localhost:7001");
Context ctx=new InitialContext(prop);
Object objref=ctx.lookup("OrderManagement");
OrderManagementHome home =
(OrderManagementHome)javax.rmi.PortableRemoteObject.narrow(
objref, OrderManagementHome.class);
OrderManagement orderManagement=home.create();
orderManagement.placeOrder("Cedric","J2EE Server Programming",1000);
orderManagement.remove();
}
catch(Exception e){
e.printStackTrace();
}
}
}
===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[email protected] and include in the body of the message "help".