How to make 2 entities map to a single class
Visual Paradigm support generate UML Class Model by analyzing the Entity Relationship Model you defined or from your database. The generated class model can then use to generate hibernate source code. By default each entity will be generated into one class model during the process. But in some situation you may want to have 2 related entities mapped to a single class model for better access of information in your program. In this article we will teach you how generate a single class for 2 entities in your model.
Suppose we have a simple entity relationship models, the Customer and Address entities. To have them both map to a single class:
- Select the master entity, let’s say the Customer, then drag out the resource icon.
- Drop it over the Address entity, and select One-to-One Relationship.
- In the Relationship Specification dialog select the primary key column in Address entity as the foreign key.
- A one-to-one relationship is now being created between Customer and Address, and with the primary key also as the foreign key.
- Right click on Address entity and select Convert to Partial Table.
- The Address entity now having Partial stereotype added. Right click on the blank area of the diagram and select Synchronize to Class Diagram.
- The Customer class is now being generated with columns from both Customer and Address entities included, which means your two entities are mapped into a single class model.
Related Know-how |
Related Link |
Leave a Reply
Want to join the discussion?Feel free to contribute!