| 特性 | 實體 Bean | 會話 Bean |
|---|---|---|
| 持久性 | 持久,不受宕機影響 | 非持久,隨服務器生命周期 |
| 標識 | 有主鍵,可查找 | 無主鍵,不可查找 |
| 共享 | 多客戶共享 | 通常專屬一客戶 |
| 生命周期 | 顯式刪除 | 非活動超時自動回收 |
equals() 和 hashCode()// Home 接口
Employee create(int arg1, String arg2, String arg3) throws CreateException, RemoteException;
// Bean 實現
public void ejbCreate(int argId, String first, String last) throws CreateException {
id = argId; setFirst(first); setLast(last);
setManagerId(0); setDepartmentId(0);
}
每個 ejbCreate 對應 ejbPostCreate,參數相同。容器調用順序:ejbCreate → 創建 EJBObject 引用 → ejbPostCreate 完成初始化。
// Home 接口
Employee findByPrimaryKey(EmployeeKey key) throws FinderException;
Enumeration findByLastLike(String pattern) throws FinderException;
Enumeration findBySalaryRange(double low, double high) throws FinderException;
返回單個 Remote 或 Enumeration。VAJ Persistence Layer 自動實現。
public interface EmployeeBeanFinderHelper {
public static final String findByIdWhereClause = "ID = ?";
public static final String findAllWhereClause = "1 = 1";
public static final String findByLastLikeWhereClause = "LAST LIKE ?";
public static final String findBySalaryRangeWhereClause = "SALARY > ? and SALARY < ?";
}