How to make 2 entities map to a single class

tomcat-thumbVisual 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:

  1. Select the master entity, let’s say the Customer, then drag out the resource icon.

    Drag out resource icon from Customer entity

    Drag out resource icon from Customer entity

  2. Drop it over the Address entity, and select One-to-One Relationship.

    Create one-to-one relationship to Address entity

    Create one-to-one relationship to Address entity

  3. In the Relationship Specification dialog select the primary key column in Address entity as the foreign key.

    Specify the primary key as the foreign key

    Specify the primary key as the foreign key

  4. A one-to-one relationship is now being created between Customer and Address, and with the primary key also as the foreign key.
  5. Right click on Address entity and select Convert to Partial Table.

    Specify Address entity as partial table

    Specify Address entity as partial table

  6. The Address entity now having Partial stereotype added. Right click on the blank area of the diagram and select Synchronize to Class Diagram.

    Synchronize ER diagram to class diagram

    Synchronize ER diagram to class diagram

  7. 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.

    Both entities are mapped into a single class

    Both entities are mapped into a single class

Related Know-how

Related Link

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply