package Beans; import java.rmi.RemoteException; import javax.ejb.CreateException; import javax.ejb.EntityBean; import javax.ejb.EntityContext; public class BonusBean implements EntityBean {
public double bonus; public String socsec; private EntityContext ctx; public double getBonus() {
return this.bonus;
} public String getSocSec() {
return this.socsec;
} public String ejbCreate(double bonus,String socsec)
throws CreateException{
//Called by container after setEntityContext this.socsec=socsec; this.bonus=bonus; return null;
} public void ejbPostCreate(double bonus,String socsec) {
//Called by container after ejbCreate
}
//These next methods are callback methods that //are called by the container to notify the //Bean some event is about to occur public void ejbActivate() {
//Called by container before Bean //swapped into memory
} public void ejbPassivate() {
//Called by container before //Bean swapped into storage
} public void ejbRemove() throws RemoteException {
//Called by container before //data removed from database
}
public void ejbLoad() {
//Called by container to //refresh entity Bean’s state
}
public void ejbStore() {
//Called by container to save //Bean’s state to database
在左边先选择实体Bean:BonusBean,在右边选择标签Entity。然后单击Deploymetn Setting按纽。将Database JNDI name 设为jdbc/Cloudscape。还要确定Create table on Deploy和Delete table on Undeploy两个复选框被选上。然后就可以单击Generate SQL,产生SQL代码了。(如果产生了数据库连接错误,那就是因为你没有启动数据库服务器。在J2EE的安装目录下的in下,启动:Cloudscape -start)