请指点一下:)

mogerdavoo 2003-05-26 08:59:26
问题:可以create实体bean,但是find不到

我直接用一个包含两个columns的表自动生成了cmp,表名是TABAREA,columns有areaid和areadef都是String,使用local接口,自动生成了create和findbyprimekey接口

用了一个无状态session bean提供远程接口封装cmp,
session bean用下面两个函数来调用cmp,并封装了create9和getInfo两个远程方法
private Context getInitialContext() throws Exception {
String url = "t3://127.0.0.1:7001";
String user = null;
String password = null;
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
}
return new InitialContext(properties);
}
catch(Exception e) {
System.out.println("Unable to connect to WebLogic server at " + url);
System.out.println("Please make sure that the server is running.");
throw e;
}
}

private TabArea9Home getAreaHome(){
try {
Context ctx =getInitialContext();
TabArea9Home home= (TabArea9Home)ctx.lookup("TabArea9");
return home;
}
catch(Exception e) {
return null;
}
}


public String creat9(String id, String def) {
TabArea9Home acpthome=getAreaHome();
try{
TabArea9 acpt=acpthome.create( id, def );
return "ok" + acpt.getAreadef() + acpt.getEJBLocalHome() + acpt.getPrimaryKey();
}
catch(Exception e) {
e.printStackTrace();
return e.getMessage();
}

}
public String getInfo(String id) {
TabArea9Home acpth=getAreaHome();
try{
TabArea9 a=acpth.findByPrimaryKey( id );
return a.getAreadef().toString();
}
catch(Exception e) {
e.printStackTrace();
return "erro" + e.getMessage();
}

}

再用客户端调试,main部分如下:
public static void main(String[] args) {
MySessionTestClient1 client = new MySessionTestClient1();
try
{
MySession session = client.create();
//System.out.println( session.creat9( "99", "333" ) );
System.out.println( session.getInfo( "99" ) );
}
catch( Exception e )
{
e.printStackTrace();
}
}




...全文
32 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧