在WebLogic6.0上实施EJB的问题(急急急急!!!)

allan2008 2002-12-17 03:04:16
当在WebLogic6.0上实施一个应用程序时在weblogic服务的启动窗口出现如下错误:

<2002-12-17 上午11时31分04秒> <Error> <J2EE> <Error deploying application ProductDemo:
Unable to deploy EJB: ProductDemo.jar from ProductDemo.jar:

In EJB Orders, method create(int,int,factory.product.LocalProduct,java.util.Date) exposes local interface types or local home interface types through the remote home interface of the bean. This is not allowed.
at weblogic.ejb20.compliance.EJBComplianceChecker.check(EJBComplianceChe
cker.java:257)
at weblogic.ejb20.compliance.EJBComplianceChecker.checkDeploymentInfo(EJ
BComplianceChecker.java:221)
........

请教各位问题出在哪?
...全文
55 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
mefaintII 2002-12-20
  • 打赏
  • 举报
回复
给你两段代码,看一下比较区别……
public EJBLocalHome getLocalHome(String jndiHomeName) throws ServiceLocatorException {
EJBLocalHome home = null;
try {
if (cache.containsKey(jndiHomeName)) {
home = (EJBLocalHome) cache.get(jndiHomeName);
} else {
home = (EJBLocalHome) ic.lookup(jndiHomeName);
cache.put(jndiHomeName, home);
}
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
return home;
}

/**
* will get the ejb Remote home factory. If this ejb home factory has already been
* clients need to cast to the type of EJBHome they desire
*
* @return the EJB Home corresponding to the homeName
*/
public EJBHome getRemoteHome(String jndiHomeName, Class className) throws ServiceLocatorException {
EJBHome home = null;
try {
if (cache.containsKey(jndiHomeName)) {
home = (EJBHome) cache.get(jndiHomeName);
} else {
Object objref = ic.lookup(jndiHomeName);
Object obj = PortableRemoteObject.narrow(objref, className);
home = (EJBHome)obj;
cache.put(jndiHomeName, home);
}
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}

return home;
}

都只是获取home的,一个是localhome一个是remotehome
mefaintII 2002-12-20
  • 打赏
  • 举报
回复
ProductLocalHome home =
(ProductLocalHome) javax.rmi.PortableRemoteObject
.narrow(initial.lookup("java:comp/env/ejb/LocalProduct"),
ProductLocalHome.class);
return home;

我已经糊涂了,在你getProduct...方法中这句话,难道localhome也要PortableRemoteObject么?
不行了不行了,熬了2个通宵,神志不清,我怎么觉得,local就是lookup
然后create就可以了?
allan2008 2002-12-19
  • 打赏
  • 举报
回复
《continue》
package factory.product;

import java.util.Collection;
import javax.ejb.*;
import java.rmi.RemoteException;

public interface ProductHome extends EJBHome {

Product create(String product, String name,
Collection routingInstructions)
throws RemoteException, CreateException;

Product findByPrimaryKey(String product)
throws RemoteException, FinderException;
}
package factory.product;

import javax.ejb.*;
import java.rmi.RemoteException;

import java.util.Collection;

abstract public interface Product extends EJBObject {
abstract public String getProduct() throws RemoteException;

abstract public String getName() throws RemoteException;
abstract public void setName(String name) throws RemoteException;

// Business methods
abstract public void addRoutingInstruction(int sequence, String instruction)
throws RemoteException;

public void deleteRoutingInstruction(int sequence)
throws NoSuchRoutingException, RemoteException;

abstract public Collection getRoutingInstructions() throws RemoteException;
abstract public void setRoutingInstructions(Collection c) throws RemoteException;

}
package factory.product;

import java.util.Collection;
import javax.ejb.*;
import java.rmi.RemoteException;

public interface ProductLocalHome extends EJBLocalHome {

LocalProduct create(String product, String name,
Collection routingInstructions)
throws CreateException;

LocalProduct findByPrimaryKey(String product)
throws FinderException;
}
package factory.product;

import javax.ejb.*;
import java.rmi.RemoteException;

import java.util.Collection;

abstract public interface LocalProduct extends EJBLocalObject {
abstract public String getProduct();

abstract public String getName();
abstract public void setName(String name);

// Business methods
abstract public void addRoutingInstruction(int sequence, String instruction);

public void deleteRoutingInstruction(int sequence)
throws NoSuchRoutingException;

abstract public Collection getRoutingInstructions();
abstract public void setRoutingInstructions(Collection c);

}
package factory.product;

import javax.ejb.*;
import java.util.Collection;
import java.util.List;
import java.util.LinkedList;
import java.util.Arrays;
import java.util.Iterator;

import java.rmi.RemoteException;

abstract public class ProductEJB implements EntityBean
{
private Collection routingInstructions = new LinkedList();

abstract public String getProduct();
abstract public void setProduct(String p);
abstract public String getName();

abstract public void setName(String name);

// Business methods

public void setRoutingInstructions(Collection c) {
routingInstructions = c;
}

public Collection getRoutingInstructions() {
return routingInstructions;
}

public void addRoutingInstruction(int sequence, String instruction) {
routingInstructions.add(new RoutingInstruction(sequence,
instruction));
}

public void deleteRoutingInstruction(int sequence)
throws NoSuchRoutingException
{
Collection instructions = getRoutingInstructions();
Iterator iter = instructions.iterator();
while (iter.hasNext()) {
RoutingInstruction ri = (RoutingInstruction) iter.next();
if (ri.sequence == sequence) {
iter.remove();
setRoutingInstructions(instructions);
return;
}
}
throw new NoSuchRoutingException();
}

public void replaceRoutingInstructions(RoutingInstruction[] newRoutingInstructions)
throws RemoteException
{
LinkedList li = new LinkedList();
for (int i = 0; i < newRoutingInstructions.length; i++) {
li.add(newRoutingInstructions[i]);
}
setRoutingInstructions(li);
}

// Framework and lifecycle methods

public String ejbCreate(String product, String name,
Collection routingInstructions)
// throws RemoteException
{
setProduct(product);
setName(name);
setRoutingInstructions(routingInstructions);
return null;
}

public void ejbPostCreate(String product, String name,
Collection routingInstructions) {}

public void ejbActivate() {}

public void ejbLoad() {}

public void ejbPassivate() {}

public void ejbRemove() {}

public void ejbStore() {}

public void setEntityContext(EntityContext ctx) {}

public void unsetEntityContext() {}
}
allan2008 2002-12-19
  • 打赏
  • 举报
回复
编译没有问题,我使用weblogic6.1的console部署上去的,你的书上的例子是在www.wrox.com上下载的吗?下面是这两个关系EntityBean的完全代码,你看看:

package factory.order;

import javax.ejb.*;
import java.rmi.RemoteException;
import java.util.Date;
import factory.product.LocalProduct;

public interface Order extends EJBObject {

public int getSalesDivision() throws RemoteException;

public int getOrderNumber() throws RemoteException;

public LocalProduct getProductOrdered() throws RemoteException;

public String getStatus() throws RemoteException;

public void cancelOrder()
throws RemoteException, OrderNotCancelableException;

public void beginManufacture() throws RemoteException;

public void completeManufacture() throws RemoteException;

public Date getDateDue() throws RemoteException;
}
package factory.order;

import javax.ejb.*;
import java.rmi.RemoteException;
import factory.product.LocalProduct;
import java.util.Date;
import java.util.Collection;

public interface OrderHome extends EJBHome {

Order create(int salesDivision, int orderNumber,
LocalProduct productOrdered,
Date dateDue) throws RemoteException, CreateException;

Order create(int salesDivision, int orderNumber,
String productOrdered,
Date dateDue) throws RemoteException, CreateException;

Order findByPrimaryKey(OrderPK order)
throws RemoteException, FinderException;

Collection findOpenOrders() throws RemoteException, FinderException;

Collection findUncompletedOrders()
throws RemoteException, FinderException;

}
package factory.order;

import javax.ejb.*;
import javax.naming.*;
import java.rmi.RemoteException;
import factory.product.LocalProduct;
import factory.product.Product;
import factory.product.ProductHome;
import factory.product.ProductLocalHome;
import java.util.Date;

abstract public class OrderEJB implements EntityBean
{
// Properties
private static final String OPEN_STATUS = "o";
private static final String DEFAULT_STATUS = OPEN_STATUS;
private static final String CANCELED_STATUS = "c";
private static final String IN_PROCESS_STATUS = "m";
private static final String COMPLETED_STATUS = "f";

abstract public int getOrderNumber();
abstract public void setOrderNumber(int orderNumber);

// CMR field
abstract public LocalProduct getProductOrdered();
abstract public void setProductOrdered(LocalProduct p);

abstract public int getSalesDivision();
abstract public void setSalesDivision(int salesDivision);

abstract public Date getDateDue();
abstract public void setDateDue(Date date);

abstract public String getInternalStatus();
abstract public void setInternalStatus(String s);

private String status;

public String getStatus() {
if (getInternalStatus().equals(OPEN_STATUS)) {
return StatusStrings.OPEN;
} else if (getInternalStatus().equals(CANCELED_STATUS)) {
return StatusStrings.CANCELED;
} else if (getInternalStatus().equals(IN_PROCESS_STATUS)) {
return StatusStrings.IN_PROCESS;
} else if (getInternalStatus().equals(COMPLETED_STATUS)) {
return StatusStrings.COMPLETED;
}
throw new EJBException("Unknown status");
}

public void cancelOrder() throws OrderNotCancelableException {
if (getInternalStatus().equals(IN_PROCESS_STATUS)
|| getInternalStatus().equals(COMPLETED_STATUS)) {
throw new OrderNotCancelableException();
}
setInternalStatus(CANCELED_STATUS);
}

public void beginManufacture() {
setInternalStatus(IN_PROCESS_STATUS);
}

public void completeManufacture() {
setInternalStatus(COMPLETED_STATUS);
}

public void ejbLoad() {}

public void ejbStore() {}

public void ejbActivate() {}

public void ejbPassivate() {}

public void ejbRemove() {}

public void setEntityContext(EntityContext ctx) {}

public void unsetEntityContext() {}

// Lifecycle and framework methods

public OrderPK ejbCreate(int salesDivision, int orderNumber,
LocalProduct productOrdered,
Date dateDue) throws CreateException
{
setSalesDivision(salesDivision);
setOrderNumber(orderNumber);
setDateDue(dateDue);
setInternalStatus(DEFAULT_STATUS);
status = DEFAULT_STATUS;

return null; // for container-managed persistence
}

public void ejbPostCreate(int salesDivision, int orderNumber,
LocalProduct productOrdered, Date dateDue)
{
setProductOrdered(productOrdered);
}

public OrderPK ejbCreate(int salesDivision, int orderNumber,
String product,
Date dateDue) throws CreateException
{
setSalesDivision(salesDivision);
setOrderNumber(orderNumber);
setDateDue(dateDue);
setInternalStatus(DEFAULT_STATUS);
status = DEFAULT_STATUS;

return null; // for container-managed persistence
}

public void ejbPostCreate(int salesDivision, int orderNumber,
String product, Date dateDue)
throws CreateException
{
// The product ordered must be set in ejbPostCreate since it's
// part of a one-one relationships
try {
ProductLocalHome productHome = getProductHome();
LocalProduct p = productHome.findByPrimaryKey(product);
setProductOrdered(p);
}
// catch (RemoteException re) {
// re.printStackTrace();
// throw new EJBException(re);
// }
catch (FinderException fe) {
fe.printStackTrace();
throw new CreateException("Product does not exist");
}

}

// Implementation helpers

private ProductLocalHome getProductHome() {
try {
InitialContext initial = new InitialContext();
ProductLocalHome home =
(ProductLocalHome) javax.rmi.PortableRemoteObject
.narrow(initial.lookup("java:comp/env/ejb/LocalProduct"),
ProductLocalHome.class);
return home;
} catch (NamingException ne) {
ne.printStackTrace();
throw new EJBException(ne);
}
}

}

renjordan 2002-12-19
  • 打赏
  • 举报
回复
应该用java.sql.date,好象util.date不对,还有你是怎么部署EJB,用JBulider吗,如果是就先Bulid和编译一下,看有没问题!如果是手工部署,请仔细检查,你用的J2EE编程指南(1.3版)我也用过,应该没啥问题!
allan2008 2002-12-18
  • 打赏
  • 举报
回复
您指的是哪两个interface?
allan2008 2002-12-18
  • 打赏
  • 举报
回复
J2EE编程指南(1.3版)《Professsional Java Server Programming J2EE 1.3 Edition》
sam1zhao 2002-12-18
  • 打赏
  • 举报
回复
你看的是哪本书?
allan2008 2002-12-18
  • 打赏
  • 举报
回复
这是书上的一个例子,可能有些设计不符合现实,如果方便的话我可以把这个例子发给你,你去测测,:)
sam1zhao 2002-12-18
  • 打赏
  • 举报
回复
不知为何要在HOME接口中使用LOCAL INTERFACE,说明在设计的时候有问题.我的理解是:ORDER和PRODUCT是一对一关系,在创建ORDER EJB时,没必要创建PRODUCT.在ORDER EJB创建完成后,再写一个方法(如addProduct)在ORDER里面加入PRODUCT
adonn 2002-12-18
  • 打赏
  • 举报
回复
exposes local interface types or local home interface types through the remote home interface of the bean. This is not allowed

local是local,remote是remote
(等于没说,呵呵)
allan2008 2002-12-18
  • 打赏
  • 举报
回复
我去掉试过了,上面的是开始的没改动的
当我把create方法中的参数factory.product.LocalProduct去掉它有报以下错:

In EJB Orders, method getProductOrdered() exposes local interface types
or local home interface types through the remote interface of the bean. This is
not allowed.
at weblogic.ejb20.compliance.EJBComplianceChecker.check(EJBComplianceChe....

sam1zhao(Sam),你好,
不知你方不方便,我想跟你用电话了了
sam1zhao 2002-12-18
  • 打赏
  • 举报
回复
每个HOME INTERFACE的CREATE方法必须有一个和其参数一摸一样的EJBCREATE方法和其对应.
我看你代码好象没有把LOCAL INTERFACE 去掉
allan2008 2002-12-18
  • 打赏
  • 举报
回复
我的应用程序中用了EJB中的关系:从订单bean(order)到产品bean(product)是一对一,而且是单向的,他们的部分代码如下:

public interface OrderHome extends EJBHome {
Order create(int salesDivision, int orderNumber,
LocalProduct productOrdered,
Date dateDue) throws RemoteException, CreateException;

Order create(int salesDivision, int orderNumber,
String productOrdered,
Date dateDue) throws RemoteException, CreateException;

Order findByPrimaryKey(OrderPK order)
throws RemoteException, FinderException;

Collection findOpenOrders() throws RemoteException, FinderException;

Collection findUncompletedOrders()
throws RemoteException, FinderException;

}

abstract public class OrderEJB implements EntityBean
{

abstract public int getSalesDivision();
abstract public void setSalesDivision(int salesDivision);
...
// Lifecycle and framework methods


public OrderPK ejbCreate(int salesDivision, int orderNumber,
LocalProduct productOrdered,
Date dateDue) throws CreateException
{
setSalesDivision(salesDivision);
setOrderNumber(orderNumber);
setDateDue(dateDue);
setInternalStatus(DEFAULT_STATUS);
status = DEFAULT_STATUS;

return null; // for container-managed persistence
}

public void ejbPostCreate(int salesDivision, int orderNumber,
LocalProduct productOrdered, Date dateDue)
{
setProductOrdered(productOrdered);
}

public OrderPK ejbCreate(int salesDivision, int orderNumber,
String product,
Date dateDue) throws CreateException
{
setSalesDivision(salesDivision);
setOrderNumber(orderNumber);
setDateDue(dateDue);
setInternalStatus(DEFAULT_STATUS);
status = DEFAULT_STATUS;

return null; // for container-managed persistence
}

public void ejbPostCreate(int salesDivision, int orderNumber,
String product, Date dateDue)
throws CreateException
{
// The product ordered must be set in ejbPostCreate since it's
// part of a one-one relationships
try {
ProductLocalHome productHome = getProductHome();
LocalProduct p = productHome.findByPrimaryKey(product);
setProductOrdered(p);
}
// catch (RemoteException re) {
// re.printStackTrace();
// throw new EJBException(re);
// }
catch (FinderException fe) {
fe.printStackTrace();
throw new CreateException("Product does not exist");
}

}
}

allan2008 2002-12-18
  • 打赏
  • 举报
回复
当我把create方法中的参数factory.product.LocalProduct去掉它有报以下错:

In EJB Orders, method getProductOrdered() exposes local interface types
or local home interface types through the remote interface of the bean. This is
not allowed.
at weblogic.ejb20.compliance.EJBComplianceChecker.check(EJBComplianceChe....

请教?

sam1zhao 2002-12-18
  • 打赏
  • 举报
回复
你的EJB的HOME INTERFACE 的CREATE方法参数中不能带有LOCAL INTERFACE的类型:"factory.product.LocalProduct",违反了EJB的LOCAL INTERFACE的原则.
mefaintII 2002-12-17
  • 打赏
  • 举报
回复
好像是ejb有问题,两个interface不匹配?

1,236

社区成员

发帖
与我相关
我的任务
社区描述
企业软件 中间件技术
社区管理员
  • 中间件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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