|
3.5 How to Model an Entity Relationship Relationships are modeled from stereotyped associations from the class diagram. You can do this by selecting an association from the pallet by clicking on the Class Diagram Drawer in the palette to open it, finding the association creation section, then drawing a line between the two entities you want to relate. Afterward making sure the association is still highlighted, add an relation stereotype using the Add Stereotype button in the stereotype tab of the properties view. The first thing to get right here is the multiplicity. Don't worry about the difference between 1, 0..1 and 1..1, or 0..n, 1..n and *. Just use 1 and *, where * stands for many. You can set the relationship to be required (a minimum of one on the relationship) elsewhere. Examples might be: an order has many order lines, whereas an order line only appears on one order so the relationship is one-to-many between order and order line. If a customer may have only one billing address, and a billing address is related to only one customer, the relationship is one-to-one. A guitar player may play in many bands, and a band may have many guitar players so the relationship is many-to-many.
These along with many-to-one form the standard relationship types by multiplicity. It is rarely worth modeling relationships more than 1 but not many (eg three-to-one, or many-to-two). Occasionally it is worth having a dual relationship modeled explicitly and this should be modeled as two separate to-one relationships. Roles should be set to the name of the entities they relate to, but starting with a lowercase letter. These manifest as accessor attributes on the entities. Most of the information about a relationship is placed on the accessor attribute, which need to be stereotyped as an end. After drawing the relationship, RSA puts attributes on each of the entities. These can be accessed most easily via the model explorer. Either go to the parent entity directly and search for the relevant attribute under the tree, or select on the entity, go into the attributes tab of the properties view, right click on the relevant entry and choose select in explorer. When the accessor attribute is selected in explorer, you can go to the stereotype tab of the properties view and use the Add Stereotype button to stereotype it as an "end". Be warned, the role name closest to the entity is not the name of the accessor attribute. It is the role name furthest away you are looking for. If Order is related to OrderLine, the role "order" will be found as an accessor attribute on the OrderLine entity, and the role "orderLine" will be found as an accessor attribute on the Order entity. The multiplicity will be set on the attribute to match the role, that is it matches the multiplicity furthest away on the diagram.
The JeeWiz properties made available by stereotyping the attributes as ends follow this same convention. The properties here mostly relate to foreign key creation or are passed up as relevant to dataview relationships applying to the automatic maintenance page creation. An exception is cascadeDelete. If this is set to true and a row in the table is deleted, the application server will delete all related rows in the related entity's table. It is possible to set the required property here. This has the effect of making a * multiplicity act as a 1..* and a 1 multiplicity act as a 1..1. This convention is closer to the entity-relation modeling convention rather than class diagram convention. There is enough on the diagram as it is and you might wish to switch off either the stereotypes or even the display entirely. If so, right click on the association, and use filters. Use Stereotype visibility style to switch off the stereotype text or hide connection labels to switch off all display. Top Tips:
Links:
Copyright © 2001-2006 New Technology / enterprise Ltd. | |||||||||||||||||||||