Local Home接口问题,请高手帮忙

04-02-25 jxin
我用Jbuilder7+Weblogic6.1+mysql开发EJB,在Session Bean 中调用Entity Bean,Entity Bean 使用Remote接口时,工作正常,当使用Local接口,在接口转换时出现ClassCastException例外,我的代码如下:

String passwd = "";

try {

Context ctx = new InitialContext();

Object ref = ctx.lookup("EOperatorRemote");

System.out.println("Remote refrence: <" + ref.toString() + ">");

System.out.println("before cast ...");

EOperatorRemoteHome oprHome = (EOperatorRemoteHome)PortableRemoteObject.narrow(ref, EOperatorRemoteHome.class);

System.out.println("after cast ...");

EOperatorRemote opr = oprHome.findByPrimaryKey("000001");

passwd = opr.getPasswd();

} catch(Exception ex) {

ex.printStackTrace();

}

System.out.println("Remote EntityBean return:<" + passwd + ">");

try {

Context ctx = new InitialContext();

Object objref = ctx.lookup("LOperator");

System.out.println("Local refrence: <" + objref.toString() + ">");

System.out.println("before cast to EJBLocalHome ...");

EJBLocalHome localHome = (EJBLocalHome)objref;

System.out.println("after cast to EJBLocalHome ...");

System.out.println("EJBLocalHome: <" + localHome.toString() + ">");

LOperatorHome oprHome = (LOperatorHome)localHome;

System.out.println("after cast to LOperatorHome ...");

LOperator opr = oprHome.findByPrimaryKey("000001");

passwd = opr.getPasswd();

System.out.println("Local EntityBean return:<" + passwd + ">");

} catch(Exception ex) {

ex.printStackTrace();

}

我对同一个表写了两个Entity Bean,EOperatorRemoteHome为远程接口,LOperatorHome为本地接口,对远程接口的调用成功返回了密码,对本地接口的调用,在 LOperatorHome oprHome = (LOperatorHome)localHome; 这条语句抛出了例外,我跟踪到JNDI的lookup后得到Object为LOperatorBean_60eynk_LocalHomeImpl,是Weblogic自动产生的,它的定义为

public final class LOperatorBean_60eynk_LocalHomeImpl

extends weblogic.ejb20.internal.EntityEJBLocalHome

implements entitybean.LOperatorHome, weblogic.utils.PlatformConstants

哪位高手能告诉我怎么回事啊?怎样才能调用本地接口的Entity Bean成功啊?

盼回复!!!

jxin
2004-02-25 14:04
怎么没人回答我的问题啊?帮帮忙啦!!!

jxin
2004-02-25 15:31
问题解决了,要在Weblogic 的 classpath 里包含Entity Bean 的 JAR包

happlyin
2004-02-25 15:53
你把session bean和entity bean放在一个ejb的jar包中,这个问题就可以解决。或者你把session bean的jar包和entity bean的jar包打成一个ear包。在部署,问题就可以解决。

这个问题是由ClassLoader引起的。

猜你喜欢