哪位给讲讲~~
另,再问一个,要在两个实体bean间建立关联,是不是一定要通过数据库相应表间建立主键和外键的关联才可以?那,这主键和外键是不是都得在实体bean的域(cmr-field)中?

解决方案 »

  1.   

    Although a particular EJB implementation may vary, it's the easiest to understand the three statements as follows:    * In your database, there is a User table and a UserInfo table. 
          They are linked through a foreign key.    * Your first create stament will create a record in the User table    * Your second create statement will create a record in the UserInfo table    * The setUserInfo call will establish the relationship between the two records.> 要在两个实体bean间建立关联,是不是一定要通过数据库相应表间建立主键和外键的关联才可以?Usually yes, but it's EJB implementation dependent.> 那,这主键和外键是不是都得在实体bean的域(cmr-field)中?It depends on the kinds of relationships.You define a CMR field on the source CMP bean if the destination bean is navigable. For example, if you have a Customer bean and an Address bean and they have a one-to-many unidirectional relationship, then only on Customer bean you need to define a CMR field "addresses" and provide methods such as getAddresses(). On Address, you shouldn't define any CMR field because Customer is not navigable from Address. 
      

  2.   

    “> 要在两个实体bean间建立关联,是不是一定要通过数据库相应表间建立主键和外键的关联才可以?Usually yes, but it's EJB implementation dependent.”按这意思,还unsusally的情况?假如不是通过表的主外键建立联系,那两个CMP的关联关系又怎么改变对应表的数据??