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
在左邊先選擇實(shí)體Bean:BonusBean,在右邊選擇標(biāo)簽Entity。然后單擊Deploymetn Setting按紐。將Database JNDI name 設(shè)為jdbc/Cloudscape。還要確定Create table on Deploy和Delete table on Undeploy兩個(gè)復(fù)選框被選上。然后就可以單擊Generate SQL,產(chǎn)生SQL代碼了。(如果產(chǎn)生了數(shù)據(jù)庫連接錯(cuò)誤,那就是因?yàn)槟銢]有啟動(dòng)數(shù)據(jù)庫服務(wù)器。在J2EE的安裝目錄下的in下,啟動(dòng):Cloudscape -start)