你直接把数据库操作写在SessionBean里不就可以了吗?再说SessionBean也没有CMP的概念啊?你是不是想说EnityBean啊?我觉得用SessionBean就可以了。

解决方案 »

  1.   

    EJB relationships
    In the EJB tools, you can use the EJB deployment descriptor editor to optionally define a relationship between different enterprise beans.It is important to note that EJB 1.x relationships are WebSphere® Application Server extensions, and EJB 2.x relationships are part of the EJB 2.0 deployment descriptor.There are three main types of relationship:one-to-one 
    one-to-many 
    and many-to-many 
    In a one-to-one (1:1) relationship, a CMP entity bean is associated with a single instance of another CMP entity bean. For example, an Employee bean could be associated with only a single instance of an EmployeeID bean, because an employee can have only one employee identifier on file.In a one-to-many (1:M) relationship, a CMP entity bean is associated with multiple instances of another CMP entity bean. For example, a Department bean could be associated with multiple instances of an Employee bean, because most departments are made up of multiple employees.In a many-to-many (M:M) relationship, multiple instances of a CMP entity bean are associated with multiple instances of another CMP entity bean. For example, multiple instances of a Customer bean could be associated with multiple instances of a Restaurant bean, because restaurants serve many customers, and customers patronize many different restaurants. For 1.1 CMP beans, a many-to-many relationship requires the use of a link bean. This link bean is placed in the middle of the two enterprise beans by creating a 1:M relationship from each bean to the link bean. For 2.0 CMP beans, the creation of the link bean is not required because the creation of the link table is handled automatically during the execution of a top-down mapping.As part of defining a relationship, you assign a role to each bean relative to the other bean, and you give that role a name. For example, suppose you create n relationship between Employee and EmployeeID. The role of EmployeeID within the Employee bean could be something meaningful like id or employeeID. The role of Employee within the EmployeeID bean could be something like employee or owner. These names are used to derive method names in the generated code and become part of the enterprise bean's remote interface.For 2.0 Relationships, the cmr-field name is used to generate methods.When CMP fields and relationships are eventually mapped to database tables, foreign keys are used to represent these relationships in the database tables. You can then add relationship roles to the key of an enterprise bean, which makes the foreign key represented in the relationship part of the key class.In order to add a role to the key of a bean, it must be single multiplicity and it must be required (e.g., 1..1). Also, the role's owning bean must have the foreign-key check box selected. The rules are the same for 2.0 CMPs except that the multiplicity will be 1 since there is no lower bound to test for requiredness. Note that the foreign-key check box is used to designate which CMP's mapped table should contain the foreign-key column. The CMP is the source enterprise bean for the role.In the above example, the employeeID role can be made part of the Employee key if the multiplicity is 1..1, and Employee has the foreign-key check box selected. Also, ing a role as required (e.g., 1..x), will add the role's type as a parameter to the Home interface's create method. In EJB 2.0 relationships, a cmr-field is required if the navigable check box is selected. You will only be able to select navigable for a CMP that has a local client view. Relationships can only be defined for the same version of CMPs. You cannot relate a 1.x and a 2.x CMP entity bean. The 2.x relationship creation wizard shows a UML view of the relationship and a specification view. Note that the multiplicity described in the specification view corresponds to the rules in the EJB 2.0 specification. It is backwards to the UML view since the multiplicity for the role is relative to the relationship, and in the UML view it is relative to the source enterprise bean.
      

  2.   

    你可以用bmp啊,cmp是只支持ejb-ql查询的,不是很灵活,但bmp可以支持sql查询,其实bmp就是自己写数据访问语句。
      

  3.   

    我是说实体bean CMP只是把它做为数据库的一个实例,具体业务放在会话bean里
    这样的观点大家认同吗?