请指点一下:)
问题:可以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();
}
}