hello
i have a entity bean(AuthorsBean),a session bean(FacadeBean),and a test client generated by jb6,the procedure is:
the client call the session bean,then the session bean call the entity bean.
in my session bean,i want to look up the home interface of the entity bean in the ejbCreate method,the code as follow:
public class FacadeBean implements SessionBean {
private AuthorsHome authorsHome=null;
SessionContext sessionContext;
public void ejbCreate() throws CreateException {
try{
System.out.println("this is ejbCreate");
Context ctx=new InitialContext();
Object ref=ctx.lookup("java:comp/env/ejb/Authors");
AuthorsHome authorsHome=(AuthorsHome)ref;
}catch(Exception e){
System.out.println(e.getMessage());
}
}
...........................
..........................
public java.lang.String getAddress()throws Exception{
Authors authors=authorsHome.findByPrimaryKey("172-32-1176");
return authors.getAddress();
}
}
}
my test client as:
............
.............
Context ctx = new InitialContext();
Object ref = ctx.lookup("Facade");
facadeHome = (FacadeHome) PortableRemoteObject.narrow(ref, FacadeHome.class);
Facade facade=facadeHome.create();
System.out.println(facade.getAddress());
..................
..................
it throw a null point exception.but if i modify the session bean to move the code block that is used to look up the "AuthorsHome" in ejbCreate method to the "getAddress" method,it works well,as follow:
public class FacadeBean implements SessionBean {
private AuthorsHome authorsHome=null;
SessionContext sessionContext;
public void ejbCreate() throws CreateException {
try{
System.out.println("this is ejbCreate");
}catch(Exception e){
System.out.println(e.getMessage());
}
}
...........................
..........................
public java.lang.String getAddress()throws Exception{
Context ctx=new InitialContext();
Object ref=ctx.lookup("java:comp/env/ejb/Authors");
AuthorsHome authorsHome=(AuthorsHome)ref;
Authors authors=authorsHome.findByPrimaryKey("172-32-1176");
return authors.getAddress();
}
}
}
why the ejbCreate can't lookup the home interface?
thanks for any helps!
i have a entity bean(AuthorsBean),a session bean(FacadeBean),and a test client generated by jb6,the procedure is:
the client call the session bean,then the session bean call the entity bean.
in my session bean,i want to look up the home interface of the entity bean in the ejbCreate method,the code as follow:
public class FacadeBean implements SessionBean {
private AuthorsHome authorsHome=null;
SessionContext sessionContext;
public void ejbCreate() throws CreateException {
try{
System.out.println("this is ejbCreate");
Context ctx=new InitialContext();
Object ref=ctx.lookup("java:comp/env/ejb/Authors");
AuthorsHome authorsHome=(AuthorsHome)ref;
}catch(Exception e){
System.out.println(e.getMessage());
}
}
...........................
..........................
public java.lang.String getAddress()throws Exception{
Authors authors=authorsHome.findByPrimaryKey("172-32-1176");
return authors.getAddress();
}
}
}
my test client as:
............
.............
Context ctx = new InitialContext();
Object ref = ctx.lookup("Facade");
facadeHome = (FacadeHome) PortableRemoteObject.narrow(ref, FacadeHome.class);
Facade facade=facadeHome.create();
System.out.println(facade.getAddress());
..................
..................
it throw a null point exception.but if i modify the session bean to move the code block that is used to look up the "AuthorsHome" in ejbCreate method to the "getAddress" method,it works well,as follow:
public class FacadeBean implements SessionBean {
private AuthorsHome authorsHome=null;
SessionContext sessionContext;
public void ejbCreate() throws CreateException {
try{
System.out.println("this is ejbCreate");
}catch(Exception e){
System.out.println(e.getMessage());
}
}
...........................
..........................
public java.lang.String getAddress()throws Exception{
Context ctx=new InitialContext();
Object ref=ctx.lookup("java:comp/env/ejb/Authors");
AuthorsHome authorsHome=(AuthorsHome)ref;
Authors authors=authorsHome.findByPrimaryKey("172-32-1176");
return authors.getAddress();
}
}
}
why the ejbCreate can't lookup the home interface?
thanks for any helps!