EJB 实体 Bean 深度解析:从诞生到查询的全方位指南
1. CMP 实体 Bean 的编程契约与要求
CMP(Container - managed persistence)为实体 Bean 类与其持久化表示提供了分离机制。在 CMP 实体 Bean 的编程过程中,有诸多规则和要求需要遵循。
- 查找方法(Finder methods) :查找方法必须以 find
为前缀,并且要抛出 javax.ejb.FinderException
。对于远程主接口的查找方法,还必须声明 java.rmi.RemoteException
。例如:
import javax.ejb.FinderException;
import java.rmi.RemoteException;
public interface RemoteEntityHome extends javax.ejb.EJBHome {
// 远程主接口的查找方法
public java.util.Collection findBySomeAttribute() throws FinderException, RemoteException;
}
- 创建方法(Create methods) :实体 Bean 的
create()
方法是可选的,但findByPrimaryKey()
方法