Previous Next
sde-vs_orm_user_guide Chapter 17 - Object Model

Chapter 17 - Object Model

Smart Development Environment for Microsoft Visio Studio .NET (SDE-VS) provides you a visual modeling environment for the object model of an application. This chapter shows you how to depict the object models by using a Class Diagram and describes how the object model maps to the data model.

In this chapter:

Introduction

An object is a self-contained entity with well-defined characteristics and behaviors while the characteristics and behaviors are represented by attributes and operations respectively. A class is a generic definition for a set of similar objects. Hence, an object is an instance of a class.

An object model provides a static conceptual view of an application. It shows the key components (objects) and their relationships (associations) within the application system. The object model can be used to generate the Java model API and .NET model API.

A visual modeling for object models is provided, not only for creating a new object model, but also for transforming from a data model. As object-relational mapping is automated, the database, code and persistent layer can be generated, which in turn streamlines the model-code-deploy software development process.

Object Models

A class diagram can be used to describe the objects and classes inside a system and the relationships between them; and thus, a class diagram is also known as an object model. The class diagram identifies the high-level entities of the system. The class diagram truly conforms to a complete UML 2.0.

The following section describes how you can depict an object model using the class diagram. The support for the generation of persistent code based on the object model will be briefly described in ORM-Persistable Class of Implementation chapter.

Creating a Class Diagram

You are provided with two ways to create a Class Diagram:

  1. Drawing a Class Diagram
  2. Synchronizing from a Data Model to an Object Model

Drawing a Class Diagram

  1. You can create a new class diagram in one of the three ways:
  2. A new class diagram pane is displayed.

Creating a new Class element to the Class Diagram
  1. On the diagram toolbar, click the Class shape icon.
  2. Figure 17.4 - The Class shape icon
  3. Click a location in the diagram pane.
  4. An icon representing the class element is added to the diagram.

  5. Type in a name for the Class element.
Creating a new ORM-Persistable Class element to the Class Diagram

ORM-Persistable class is capable of manipulating the persistent data with the relational database. Classes added to the class diagram can be stereotyped as ORM Persistable to manipulate the database. For information on how to specify the stereotype of a class, refer to Setting Stereotypes of classes to be ORM Pesistable section.

There is an alternative way to add the ORM-Persistable class easily.

  1. On the diagram toolbar, click the Class shape icon and hold for a while, a pop-up menu shows.
  2. Figure 17.5 - Hold mouse on the Class shape icon
  3. Select ORM-Persistable Class from the pop-up menu.
  4. Figure 17.6 - Select ORM-Persistable Class
  5. Click a location in the diagram pane.
  6. A class shape icon which is marked with <<ORM Persistable>> is added to the diagram.

  7. Type a name for the ORM-Persistable Class.
Modifying the Class Specification

A class specification displays the class properties and relationships.

You can display the Class Specification in one of the two ways:

Class Specification dialog box is displayed, you can modify class properties and relationships.

Figure 17.8 - Class Specification dialog
Adding new Attribute to the Class

An attribute is a property of a class which has a name, a value and also has a type to describe the characteristic of an object.

  1. You can add attribute to the class in one of the three ways:
Adding Association to the Classes

An association refers to the relationship specifying the type of link that exists between objects. It shows how the objects are related to each other.

  1. You can add an association to the classes in one of the three ways:
  2. A line indicating a connection between the two classes is shown.

Editing Association Specification

You can edit the association specification in one of the three ways:

As you have completed the class diagram, you can set the stereotypes of the classes to be ORM Persistable while the Class Diagram can be transformed into Entity Relationship Diagram.

Setting Stereotypes of classes be ORM Persistable

Stereotype extends the semantics of the UML metamodel. It classifies the element in what respects it behaves as an instance of metamodel. In order to enable the mapping between object model and relational database, the class has to be stereotyped as ORM persistable.

  1. Right-click a class, select Stereotypes > Stereotypes....
  2. Figure 17.17 - To add/edit an stereotypes

    The Class Specification dialog box is shown with Stereotypes Tab

    Figure 17.18 - Class Specification dialog (Stereotypes Tab)
  3. Select ORM Persistable, then > button and OK.
  4. Figure 17.19 - Classes with Stereotypes

Synchronizing from a Data Model to an Object Model

You can generate a Class Diagram from an ERD by synchronization if there is an ERD.

  1. You can synchronize the ERD to Class Diagram in one of the three methods:
  2. A Class Diagram is generated and can be found under the Diagram Navigator.

    Figure 17.23 - The Class Diagram generated from ERD

Defining Package for Classes

There are two ways to define the packages for the classes.

After defining the packages to the classes, the classes are inside the package and depicted on the class repository.

Figure 17.28 - The Model pane show the classes is in the package

Specifying Inheritance Strategy

In a generalization, the subclass inherits all the features of the superclass. Two inheritance strategies - table per class hierarchy and table per subclass are provided for transforming the generalization hierarchy to relational model. By default, table per class hierarchy is used for the generalization.

When transforming generalization into relational model, the generalization is transformed according to the inheritance strategy applied. For more information on the transformation, refer to the description of Mapping Inheritance/Generalization section.

You can specify the inheritance strategy in one of the two ways:

These two inheritance strategies can be applied to different subclasses within a generalization hierarchy in Java project. Applying two strategies to different subclasses within a generalization in .NET project will result in error when the generation of code and database.

Specifying Collection Type

If one end of an association contains a multiplicity of many, a collection class will be generated for handling the multiple instances. You are allowed to specify the type of collection, including set, bag, list and map.

Set is an unordered collection that does not allow duplication of objects. Bag is an unordered collection that may contain duplicate objects. List is an ordered collection that allows duplication of objects. Map is an ordered collection that maps keys to values while each key can map to exactly one value.

For more information on the usage of Collection in Java code, refer to the description of Using Collection with Smart Association Handling and Using Collection with Standard Association Handling in the Manipulating Persistent Data with Java chapter.

For more information on the usage of Collection in .NET source code, refer to the description of Using Collection with Smart Association Handling and Using Collection with Standard Association Handling in the Manipulating Persistent Data with .NET chapter.

  1. Right-click on the connection line, click Open Specification from popup menu.
  2. Figure 17.34 - To Open specification
  3. Click the ORM Association Detail Tab, select the Collection Type from the drop-down menu.
  4. Figure 17.35 - ORM Association Detail Tab

Defining ORM Qualifier

ORM Qualifier is used to specify the extra retrieval rules of the generated persistent class querying the database. You are allowed to define the ORM Qualifiers of the classes in the class diagram before the generation of persistent code. For more information on the usage of ORM Qualifier, refer to the description of Using ORM Qualifier in the Manipulating Persistent Data with Java and Manipulating Persistent Data with .NET chapter.

  1. Right-click on a class that you want to add extra retrieval rules, click Open Specification.
  2. Figure 17.36 - Class Specification dialog (ORM Qualifiers Tab)
  3. Click the ORM Qualifiers Tab, then click Add.
  4. Figure 17.37 - ORM Qualifier Specification dialog

    ORM Qualifier Specification (ORM Qualifiers) dialog box is displayed with a list of attributes of the selected class.

  5. Enter the name of the ORM Qualifier, place a check mark for the Key column of the attribute that will be used in querying the database.
  6. Figure 17.38 - ORM Qualifier Specification (ORM Qualifiers) dialog

Customizing SQL

Ready-to-use SQL statements will be generated and used by the persistent code to directly manipulate the database. In some cases, you may find the generated SQL statements not appropriate for your needs. You are allowed to override the generated SQL statements, including the Insert, Update and Delete statements whenever you want to.

To customize the generated SQL statements:

  1. Right-click on an ORM-Persistable class that you want to customize the SQL statements, select ORM > ORM Class Detail...from the pop-up menu. The Class Specification dialog box showing the ORM Class Detail tab is displayed.
  2. Figure 17.39 - To open ORM Class Details
  3. Select the type of SQL statement that you want to customize.
  4. Figure 17.40 - Class Specification dialog (ORM Class Detail Tab)
  5. Click Generate SQL to generate the ready-to-use SQL statement.
  6. Figure 17.41 - To generate insert SQL statement
    The SQL statement is generated based on the property of class.
    Figure 17.42 - The basic insert SQL statement is generated
  7. Modify the SQL statement to the desired one.
  8. Figure 17.43 - Customize the insert SQL statement

Mapping an Object Model to a Data Model

Object Relational Mapping (ORM) is supported which maps object models to entity relational models and vice versa.

Mapping between objects to relational database preserves not only the data, but also the state, foreign/primary key mapping, difference in data type and business logic. Thus, you are not required to handle those tedious tasks during software development.

Mapping Classes to Entities

Object Model can be mapped to Data Model due to the persistent nature of classes. Persistent classes can act as persistent data storage during the application is running. And hence, all persistent classes can map to entities using a one-to-one mapping.

Example:

Figure 17.44 - Mapping Classes to Entities

In the above example, the Customer Class is mapped with the Customer Entity as the Customer instance can store the customer information from the Customer Entity.

Mapping attributes to columns

Since the persistent classes map to the entities, persistent attributes map to columns accordingly. All non-persistent attributes such as derived values are ignored during the transformation.

Example:

Figure 17.45 - Mapping attributes to columns

In the above example, the following table shows the mapping between the attributes of the Customer Class and the columns of the Customer Entity.

Customer Class Customer Entity
CustomerID CustomerID
CustomerName CustomerName
Address Address
ContactPhone ContactPhone
Email Email
Table 17.1

Mapping Data Type

The persistent attribute type automatically maps to an appropriate column data type of the database you desired.

Example:

Figure 17.46 - Mapping data type

In the above example, the following table shows the mapping between data types

Customer Class Customer Entity
int int (10)
String varchar(255)
Table 17.2

A table shows the data type mapping between Object model and Data model.

Object Model Data Model
Boolean Bit (1)
Byte Tinyint (3)
Byte[] Binary(1000)
Blob Blob
Char Char(1)
Character Char(1)
String varchar(255)
Int Integer(10)
Integer Integer(10)
Double Double(10)
Decimal Integer
Bigdecimal Decimal(19)
Float Float(10)
Long Bigint(19)
Short Smallint(5)
Date Date
Time Time(7)
Timestamp Timestamp(7)
Table17.3

Mapping Primary Key

You can map an attribute to a primary key column. When you synchronize the ORM-Persistable Class to the ERD, you will be prompted by a dialog box to select primary key.

Example:

Figure 17.47 - Select the primary key

In the above example, when synchronizing the class of Product to entity relationship diagram, the above dialog box is shown to prompt you to select the primary key of the Product class.

Under the drop-down menu, you can select either one of the attributes of the Product class to be the primary key, or assign SDE-VS to generate the primary key automatically, or select "Do Not Generate" to leave the generated entity without primary key.

Figure 17.48 - Generate/Specific a primary key

The above diagram shows if you assign ProductID as primary key, the ProductID of the generated entity, Product will become bold; whereas if you select "Auto Generate" for the primary key, an additional attribute ID is generated as the primary key of the Product entity.

Mapping Association

Association represents a binary relationship among classes. Each class of an association has a role. A role name is attached at the end of an association line. The role name maps to a phrase of relationship in the data model.

Mapping Aggregation

Aggregation is a stronger form of association. It represents the "has-a" or "part-of" relationship.

Example:

Figure 17.49 - Mapping aggregation

In the above example, it shows that a company consists of one or more department while a department is a part of the company.

You have to give the role names, "ConsistsOf" and "is Part Of" to the classes, Company and Department in the association respectively in order to proceed to the generation of code.

Mapping Composite Aggregation

Composite aggregation implies exclusive ownership of the "part-of" classes by the "whole" class. It means that parts may be created after a composite is created, meanwhile such parts will be explicitly removed before the destruction of the composite.

Example:

Figure 17.50 - Mapping Composite Aggregation

In the above example, the Primary/Foreign Key Column Mapping is automatically executed. StudentID of the student entity is added to the entity, EmergencyContact as primary and foreign key column.

Mapping Multiplicity

Multiplicity refers to the number of objects associated with a given object. There are six types of multiplicity commonly found in the association. The following table shows the syntax to express the Multiplicity.

Table shows the syntax expressing the Multiplicity

Type of Multiplicity Description
0 Zero instance
0..1 Zero or one instances
0..* Zero or more instances
1 Exactly one instance
1..* One or more instances
* Unlimited number of instances
Table 17.4

Example:

Figure 17.51 - Mapping multiplicity

In the above example, it shows that a parent directory (role: host) contains zero or more subdirectories (role: accommodated by).

When transforming a class with multiplicity of zero, the foreign key of parent entity can be nullable in the child entity. It is illustrated by the DirectoryID.

Figure 17.52 - Column specification dialog

Table shows the typical mapping between Class Diagram and Entity Relationship Diagram.

Class Diagram Entity Relationship Diagram
Table 17.5

Mapping Many-to-Many Association

For a many-to-many association between two classes, a Link Entity will be generated to form two one-to-many relationships in-between two generated entities. The primary keys of the two entities will migrate to the link entity as the primary/foreign keys.

Example:

Figure 17.53 - Mapping Many-to-many Association

In the above example, the link entity, Student_Course is generated between entities of Student and Course when transforming the many-to-many association.

Mapping Inheritance/Generalization

Generalization distributes the commonalities from the superclass among a group of similar subclasses. The subclass inherits all the superclass��s attributes and it may contain specific attributes.

Two strategies are provided for transforming the generalization hierarchy to relational model. The two strategies for transformation are table per class hierarchy and table per subclass. For information on how to specify the inheritance strategy to subclasses, refer to the description of Specifying Inheritance Strategy section.

Using Table per Class Hierarchy Strategy

Transforming generalization hierarchy to relational model with the table per class hierarchy strategy, all the classes within the hierarchy will be combined into one single entity containing all the attributes, and a discriminator column will also be generated to the entity. The discriminator is a unique value identifying the entity which hierarchy it belongs to.

By using the table per class hierarchy strategy, the time used for reading and writing objects can be saved. However, more memory is used for storing data. It is useful if the class will be loaded frequently.

Example:

Figure 17.54 - Using Table per Class Hierarchy Strategy

In the above example, it shows how the generalization with CheckingAccount, SavingsAccount and their superclass, BankAccount is transformed by applying the table per class hierarchy strategy.

Using Table per Subclass Strategy

When a generalization hierarchy using the table per subclass strategy is transformed to relational model, each subclass will be transformed to an entity with a one-to-one identifying relationship with the entity of the superclass.

By using the table per subclass strategy, it can save memory for storing data. However, it takes time for reading and writing an object among several tables which slows down the speed for accessing the database. It is useful if the class, which contains a large amount of data, is not used frequently.

Example:

Figure 17.55 - Using Table per SubClass Strategy

In the above example, it shows how the generalization which applies the table per subclass hierarchy strategy is transformed to the CheckingAccount and SavingsAccount.

Using Mixed Strategies

The two inheritance strategies are allowed to be applied to different subclasses within a generalization hierarchy in Java project. By applying different strategies to different subclasses within a generalization hierarchy, the generalization hierarchy will be transformed with respect to the specified inheritance strategies.

Example:

Figure 17.56 - Inheritance Strategy dialog

Applying the above inheritance strategy to the generalization with the ChequePayment and CreditCardPayment and their superclass, Payment, two entities are resulted after transformation as shown below.

Figure 17.57 - Using Mixed Strategy

In the above example, it shows that applying table per hierarchy inheritance strategy will result in combining the attributes of the superclass and subclass into one single entity while table per subclass will result in forming an entity of subclass and a one-to-one identifying relationship between entities of superclass and subclass.

Applying two inheritance strategies to different subclasses within a generalization hierarchy is only available in Java project. If mixed strategies are applied to the generalization hierarchy in .NET project, it will result in error when the generation of code and database.

Mapping Collection of Objects to Array Table

For a persistent class acting as persistent data storage, it may consist of a persistent data containing a collection of objects. The Array Table is promoted to be used to allow users retrieve objects in the form of primitive array.

When transforming a class with an attribute of array type modifier, this attribute will be converted to an Array Table automatically. The generated entity and the array table form a one-to-many relationship.

Example:

Figure 17.58 - Mapping Collection of Object to Array Table

In the above example, the phonebook has a contact entry for each contact person. Each contact person may have more than one phone numbers. In order to ease the retrieval of a collection of phone objects, the phone attribute is converted into a ContactEntry_Phone array table.

Mapping Object Model Terminology

Table shows the shift from Object model to data model terminology.

Object Model Term Data Model Term
Class Entity
Object Instance of an entity
Association Relationship
Generalization Supertype/subtype
Attribute Column
Role Phrase
Multiplicity Cardinality
Table17.6

Showing Mapping between Object and Data Models by ORM Diagram

In order to identify the mapping between the object and data models clearly, an ORM diagram is provided to show the mappings between the ORM-Persistable class and its corresponding entity.

As you are allowed to name the ORM-Persistable class and its corresponding entity differently, and also the attributes and columns as well, you may find it difficult to identify the mappings not only between the ORM-Persistable classes and the corresponding entities, but also the attributes and columns. Taking the advantage of ORM diagram, the mappings between ORM-Persistable classes and entities and between attributes and columns can be clearly identified.

There are two ways to create the ORM diagram for showing the mapping between the object and data models:

  1. Creating an ORM diagram from the existing class diagram and/or ERD.
  2. Drawing an ORM Diagram

Creating an ORM Diagram from Existing Diagrams

The following example shows you how to show the mapping between the existing object and data models by the ORM diagram.

Let us assume the following class diagram has been created and synchronized to the entity relationship diagram (ERD).

Class Diagram Synchronized ERD
Table 17.7

You can create an ORM diagram by either the object model, data model, or both. The following steps show you how to create the ORM diagram by using the object model.

  1. Right-click on the class diagram, select Send to > ORM Diagram > New ORM Diagram from the pop-up menu.
  2. Figure 17.59 - Send Class Model to a new ORM Diagram
A new ORM diagram is created which displays the ORM-Persistable classes.
Figure 17.60 - The Class Model in ORM Diagram
Alternatively, you can create the ORM diagram from the data model by right-clicking on the ERD, and selecting Send to > ORM Diagram > New ORM Diagram from the pop-up menu.
  1. Mouse over the ORM Persistable class, click the Class-Entity Mapping - > Entity resource.
  2. Figure 17.61 - Mapping class to entity
  3. Drag the resource on the ORM diagram to show the corresponding entity associated in the mapping.
  4. Figure 17.62 - A Entity created with mapping to the Class
    A class-to-entity mapping is shown on the diagram.
    Figure 17.63 - Mapping between classes and entities
  5. By repeating steps 2 and 3, all class-to-entity mappings for all classes can be shown.
  6. If you have created the ORM diagram from the data model, you can show the class-to-entity mapping by dragging the Class-Entity Mapping - > Class resource.
    Figure 17.64 - "Class-Entity Mapping" Resource-centric on Entity

Drawing an ORM Diagram

  1. You can create a new ORM diagram in one of the three ways:
  2. A new ORM diagram is displayed.

Creating ORM-Persistable Class and Mapping Entity to the ORM Diagram

After created a new ORM diagram, you can create ORM-Persistable class and its mapping entity on the ORM diagram.

To create an ORM-Persistable class on ORM diagram:

  1. On the diagram toolbar, click ORM-Persistable Class shape icon.
  2. Figure 17.68 - ORM-Persistable Class icon button
  3. Click a location in the diagram pane.
  4. A class shape icon which is marked with <<ORM-Persistable>> is added to the diagram.

  5. Type the name for the ORM-Persistable Class.
Creating Associated ORM-Persistable Class to the ORM Diagram

You can create an associated ORM-Persistable class by using the association resources of an ORM-Persistable class.

  1. Mouse over the ORM-Persistable class, drag the One-to-One Association - > Class resource to the diagram to create another ORM-Persistable class with a one-to-one directional association.
  2. Figure 17.70 - "One-to-one Association -> Class" resource-centric
  3. Enter the name to the newly created class.
  4. Figure 17.71 - A class is created with One-to-one association
Creating Mapping Entity to the ORM Diagram

To create the mapping entity of the ORM-Persistable class:

  1. Mouse over the ORM-Persistable class, click and drag the Class-Entity Mapping - > Entity resource to the diagram.
  2. Figure 17.72 - "Class-Entity Mapping -> Entity" resource-centric
    The corresponding mapping entity, Student is created automatically.
    Figure 17.73 - The Student entity is created
  3. Create the mapping entity of Profile class by using the Class-Entity Mapping - > Entity resource.
  4. Figure 17.74 - Profile entity is created
    You can create the Entity and the mapping ORM-Persistable class using the same approach of Creating ORM-Persistable Class and Mapping Entity by using the Entity icon on the diagram toolbar and the Class-Entity Mapping - > Class resource.

Showing Attribute Mapping

The object-relational mapping exists not only between the ORM-Persistable class and entity, but also the attributes and columns. You can investigate the mapping between the attributes and columns by using the Attribute Mapping feature.

To view the attribute mapping:

  1. Right-click on the ORM diagram, select View > Attribute Mapping from the pop-up menu.
  2. Figure 17.75 - Switch to Attribute Mapping view

    The class-to-entity mapping shown on the ORM diagram is changed to attribute-to-column mapping automatically.

    Figure 17.76 ORM Diagram show the Attribute Mapping

Supporting Real-time Synchronization

ORM diagram supports real-time synchronization; that is, any change in the class diagram, entity relationship diagram and/or ORM diagram will automatically synchronize to each other.

Let us take the ORM diagram created in the Drawing ORM Diagram section as an example to modify the ORM-Persistable Class and Entity.

Forming a Class Diagram

You can create a class diagram from the existing

  1. Create a new class diagram by using New Class Diagram icon.
  2. Select the classes from the Class Repository, drag to the newly created class diagram.
  3. Figure 17.77 - Drag a classes to Class Diagram
    Figure 17.78 - The classes created with association

    The following class diagram is created.

Modifying ORM-Persistable Class

You can modify the ORM-Persistable class such as renaming the class name and adding attributes to the class.

  1. Right-click the Student class, select Add > Attribute from the pop-up menu.
  2. Figure 17.79 - Add an attributes to class

    An attribute is added to the Student class, and the mapping attribute is added to the mapping Student entity automatically.

    Figure 17.80 - The column created automatically
  3. Enter "StudentID : String" to the attribute of Student by double-clicking on the attribute. The type of the mapping column is mapped to varchar(255) automatically.
  4. Figure 17.81 - Auto mapping data type
Modifying Entity

You can modify the entity such as renaming the entity name and adding columns to the entity.

  1. Rename the column of Student entity from attribute to ID by double-clicking on it.
  2. Figure 17.82 - Change column name
  3. Right-click the Student entity, select New Column from the pop-up menu.
  4. Figure 17.83 - Create new column

    A new column is added to the Student entity and the corresponding attribute is added to the Student ORM-Persistable class automatically.

    Figure 17.84 - Attribute created automatically
  5. Enter "Name : varchar(255)" to the column by double-clicking on it. The type of the mapping attribute is mapped to String automatically.
  6. Figure 17.85 - Automatic mapping data type
  7. Double-click the column attribute of the Student class, rename from column to Name.
  8. Figure 17.86 - Change column name
  9. Modify the classes and entities on the ORM diagram as shown below:
  10. Figure 17.87 - Modified the Classes and Entities
  11. Navigate to the class diagram, the class diagram is updated automatically.
  12. Figure 17.88 - The classes in Class diagram updated automatically

Switching the View of Mapping

As ORM diagram provides two views of mapping, including the mapping between ORM-Persistable class and entity (called Class Mapping), and the mapping between attributes and columns (called Attribute Mapping).

To change the view of mapping, right-click on the ORM-diagram, select the desired view from the sub-menu of View.

Figure 17.89 - Switch to Attribute mapping

By selecting the View > Attribute Mapping from the pop-up menu, the class-to-entity mapping shown on the ORM diagram is changed to attribute-to-column mapping automatically.

Figure 17.90 - ORM Diagram show the attribute mapping

Using ORM Pane

An ORM pane is provided to generate persistent model and entity from an existing object model in Java classes and database respectively. Using the ORM pane, the existing object model and database will be transformed to ORM-Persistable class and entity; you can further develop the ORM-Persistable classes and entities by adding the desired classes and entities to the class diagram and entity relationship diagram respectively.

The ORM pane provides two views, including Class View and Database View. The class view allows you to transform the existing object model to class model while the database view allows you to transform the existing database to entity.

Figure 17.91 - ORM Pane

Class View

As the class view of the ORM pane supports the transformation of the existing object model into ORM-Persistable class, you are allowed to further your development based on the transformed object model.

  1. Select the Class View of the ORM pane.
  2. Click the Classpath Configuration icon.
  3. Figure 17.92 - Classpath Configuration

    The Select Classpaths dialog box is displayed.

    Figure 17.93 - Select Classpaths dialog
  4. Click Add...button to select the desired classpath.
  5. Figure 17.94 - Select Classpaths dialog show the selected classpath

    All the available classes found from the specified classpath(s) are transformed and shown on the ORM pane.

    Figure 17.95 - ORM Pane show the classes in the classpath
  6. Create a new class diagram by using the New Class Diagram icon.
  7. Select the desired classes and drag to the class diagram.
  8. Figure 17.96 - Drag the desired classes to Class Diagram

    The classes are added to the class diagram such that you can further develop the model by using the visual modeling feature.

    Figure 17.97 - The classes show in the Class Diagram

Database View

As the database view of the ORM pane supports the transformation of the existing database into entity, you are allowed to alter the database schema by modeling with the entity relationship diagram and exporting to the existing database.

  1. Select the Database View of the ORM pane.
  2. Figure 17.98 - Switch to database view
  3. Click the Database Configuration icon.
  4. Figure 17.99 - Database configuration

    The Database Configuration dialog box is displayed.

    Figure 17.100 - Database Configuration dialog
  5. Configure the database connection by using the Database Configuration dialog box. Refer to the description in the Getting Started with Object-Relational Mapping chapter for information on how to configure the database in the Database Configuration for Java Project and Database Configuration for .Net Project sections. If the database is successfully connected, the tables of the connected database are transformed into entities and shown on the ORM pane.
  6. Figure 17.101 - ORM Pane the reversed tables
  7. Create a new entity relationship diagram by using the New Entity Relationship Diagram icon.
  8. Select the desired entities from the ORM pane, drag to the entity relationship diagram.
  9. Figure 17.102 - Drag the desired entities to ERD
The selected entities are added to the class diagram allowing
Figure 17.103 - The Entities show on ERD

Reverse Engineering Java Classes to Object Model

You can reverse engineer the Java classes into object model with ORM-Persistable stereotyped.

To reverse engineer Java classes:

  1. On the menu, click Modeling > ORM > Reverse Java Classes....
  2. Figure 17.104 - To reverse Java Classes
    The Reverse Java Classes dialog box is displayed.
    Figure 17.105 - Reverser Java Classes dialog
  3. Click Add...to select the classpath of the Java classes to be reversed. The classpath can be a folder, zip file or jar file. After finished selecting the classpath, the classpath is added to the list of Select Classpaths, and the classes identified from the classpath are shown in the list of Available Classes.
  4. Figure 17.106 - Reverse Java Classes dialog show the classes in the classpaths
  5. Select the desired classes by using the list of buttons between the list of Available Classes and Selected Classes.
  6. Figure 17.107 - Select available classes to reverse
  7. Click OK. The selected classes are reverse engineered to class models which can be found under the Model tree.
  8. Figure 17.108 - The reversed classes show in Model Pane
To work on the reversed class models, simply add the reversed models to the
  1. Create a new class diagram by using the New Class Diagram icon.
  2. Select the classes from the Model tree, drag the classes to the newly created class diagram.
  3. Figure 17.109 - Drag the classes to Class Diagram

    The classes are added to the class diagram accordingly. The classes shown on the class diagram are stereotyped as ORM Persistable; meaning that the Java classes are reversed engineered to ORM Persistable classes supporting the object relational mapping.

    Figure 17.110 - The classes show on Class Diagram

Reverse Engineering Hibernate Model to Object Model

You are allowed to reverse engineer not only the Java classes, but also the hibernate model to object model with ORM-Persistable stereotyped. The database configuration is also reverse engineered as the database setting is defined in the hibernate model.

To reverse engineer Hibernate model:

  1. On the menu, click Modeling > ORM > Reverse Hibernate....
  2. Figure 17.111 - Reverse Hibernate

    The Reverse Hibernate Model dialog box is displayed.

    Figure 17.112 - Reverse Hibernate Model dialog
  3. Select the path of the Hibernate xml files by using the button.
  4. Select the type of reverse engineering to be performed from the drop-down menu of Reverse, either Configuration and Mapping, Configuration only or Mapping only.
  5. Figure 17.113 - Select the type of reverse engineering to performed
  6. Click OK. The hibernate model are reverse engineered to class models and entities which can be found under the Model tree.
  7. Figure 17.114 - The reversed classes show in Model Pane

After reverse engineered the hibernate model, you can use an ORM diagram to view the mapping between the reversed classes and entities. For more information on ORM diagram, refer to the description of Showing Mapping between Object and Data Models by ORM Diagram section.

  1. Create a new ORM diagram by using the New ORM Diagram icon.
  2. Add the reversed classes to the ORM diagram by dragging the class models from the Model tree to the ORM diagram.
  3. Figure 17.115 - The class show on ORM Diagram
  4. Drag the entities from the Model tree to the ORM diagram to add the entities to the ORM diagram.
  5. Figure 17.116 - The entities and classes show on ORM Diagram
  6. Right-click the ORM diagram, select View > Attribute Mapping from the pop-up menu.
  7. Figure 17.117 - Switch to Attributes mapping view
    The mapping between the attributes of class models and columns of entities are shown.
    Figure 17.118 - ORM Diagram show the attribute mapping

You can also check the reversed engineered database connection by the following steps:

  1. Click the Database Configuration icon, to open the Database Configuration dialog box.
  2. Figure 17.119 - Database Configuration dialog
  3. Select the connected database from the Database Configuration dialog box, the Database Setting is shown which shows the database configuration has been reversed successfully.
  4. Figure 17.120 - Database Setting

Previous Next
Visual Paradigm International Limited
Website: www.visual-paradigm.com
E-mail: support@visual-paradigm.com