但我用Borland白皮书上介绍的方法去做,用它的数据库例子,也存在上面提到的问题,不过第一次编译可以通过,然而第一次编译过以后那条线就消失了 再次编译时就会出现上面说的问题The Customer and Sales tables have a one-to-many relationship that needs to be reflected in the entity beans. Right-click the customer entity bean in the EJB designer and select create relationship. End the relationship on the sales entity bean. Figure 14: Create relationship in EJB designer Select the newly created sales field in the customer bean to view/edit the Relationship properties. None of these properties needs editing for this example. CustomerBean.java. Import the following packages: import java.util.*; import javax.rmi.*; Add the following method: public String totalSales() { float totalSales = 0; Collection salesCollection = getSales(); try { Iterator iterator = salesCollection.iterator(); while (iterator.hasNext()) { Object object = iterator.next(); Sales sales = (Sales) PortableRemoteObject.narrow(object, Sales.class); totalSales += sales.getTotalValue().intValue(); } } catch(Exception e) { e.printStackTrace(); totalSales = 0; } return new Float(totalSales).toString(); } In the EJB designer select the totalSales method on the customer bean and expose it through the remote interface. Figure 16: Expose method through remote interface in EJB designer Make the project (Project| Make Project “EBTutorial.jpx”).
再次编译时就会出现上面说的问题The Customer and Sales tables have a one-to-many relationship
that needs to be reflected in the entity beans. Right-click the
customer entity bean in the EJB designer and select create
relationship. End the relationship on the sales entity bean.
Figure 14: Create relationship in EJB designer
Select the newly created sales field in the customer bean to
view/edit the Relationship properties. None of these properties
needs editing for this example.
CustomerBean.java.
Import the following packages:
import java.util.*;
import javax.rmi.*;
Add the following method:
public String totalSales() {
float totalSales = 0;
Collection salesCollection = getSales();
try {
Iterator iterator = salesCollection.iterator();
while (iterator.hasNext()) {
Object object = iterator.next();
Sales sales = (Sales) PortableRemoteObject.narrow(object,
Sales.class);
totalSales += sales.getTotalValue().intValue();
}
}
catch(Exception e) {
e.printStackTrace();
totalSales = 0;
}
return new Float(totalSales).toString();
}
In the EJB designer select the totalSales method on the
customer bean and expose it through the remote interface.
Figure 16: Expose method through remote interface in EJB designer
Make the project (Project| Make Project “EBTutorial.jpx”).