How many relationships can create in EJB?
Hello,
Can anyone suggest me in how many ways can we create an relationships in EJB, I am little bit aware about some of them but want to know more about it, this may help me to create some relationships in my project work.
Any suggestions would be appreciated.
Thanks
Re: How many relationships can create in EJB?
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 more than one employee.
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 EJB 1.1 CMP entity 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 EJB 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.
Re: How many relationships can create in EJB?
In EJB's ManyToMany Relationships Following Entities are coded:
Home Entity
Home has a many to many relationship with Person. A person can have zero or more homes, and a home can have zero or more persons.
Person Entity
Person has a one to many relationship with UserRole. A person can have zero or more UserRoles's. A user role has one person associated with it.
UserRole Entity
UserRole has a many to one relationship with Role. A Role can have zero or more UserRole's, but a UserRole has only one Role.
Entity Relationships
In essence the Home - Person is a many to many relationship, where the link table is left to the EJB container to work out. The Person - Role relationship, is also a many to many relationship, but in this case, the link table is implemented manually, and the relationships are broken down using one to many and many to one relationships.
Below is the diagram of the resulting database tables.