In this tutorial, you see how to use JDeveloper to perform offline database development. You learn to create a logical model using a UML class diagram and transform it to a physical model. You also reverse engineer database definitions into class definitions and see the limits of the reverse process.

Use the UML class diagram to model a collection of static elements such as classes and types, their contents, and relationships, as well as visually create or inspect classes, interfaces, attributes, operations, associations, generalizations and realizations. Class diagrams are used for a wide variety of purposes, from high-level conceptual models to physical data models.

show more or less

Like other modeling artifacts data models can be used for a variety of purposes, from high-level conceptual models to physical data models. From the point of view of an object-oriented developer data modeling is conceptually similar to class modeling. With data modeling you identify entity types whereas with class modeling you identify classes. 

Traditional data modeling is different from class modeling because it focuses solely on data – class models allow you to explore both the behavior and data aspects of your domain, with a data model you can only explore data issues. 

As a database designer you have been asked to create a Class diagram for modeling your database objects. Using the UML class diagram, you create the logical model. After that, you transform the class diagram into a physical model. You discover how the transformer behaves and you create new datatypes and use stereotypes to take control over the transformer behavior. You see how to create multiple physical models depending on the database types you need to work with. Finally, starting from the database diagram, you reverse it into a UML class diagram and observe what differences exist with the original class diagram.

Purpose Duration Application

In this tutorial, you use Oracle JDeveloper 11g Version 11.1.2 to create a UML class model, use stereotypes, create custom datatypes and generate database definitions. You then create a database diagram and transform it back into a Class diagram.

50 minutes Download application
Part 1: Creating a Logical UML Class Model
In this section, you assume the role of a database designer and create a UML class model. You define classes with attributes and use some of the UML modeling components to represent the data point of view needed of your application.
The class modeler allows you to model classes in a database design approach. Show more or lessRead more... The class modeler can transform classes as database definitions allowing you to create stereotypes to take control over the default transformation rules natively implemented in JDeveloper.
Step 1: Create the Model Project
This topic guides you through the process of creating an application and a project without using any predefined template. You then customize the project to enable JDeveloper's database functionality.
  1. Start JDeveloper by selecting Start > All Programs > Oracle Fusion Middleware 11.1.2 > JDeveloper Studio 11.1.2

  2. If prompted for a Role, choose Database Developer and click OK.

    Select Role dialog at startup
  3. Close the Tip of the Day window.

    Once loaded, the JDeveloper IDE appears. Show more or lessRead more...
    The very first time you open JDeveloper, the Start Page displays. Notice the various options available to help you learn about JDeveloper. After exploring these options, click the X on the Start Page tab to close it. (the X appears when you mouse over the tab).
    You can re-invoke the Start Page later by choosing Help | Start Page.

    JDeveloper Start Page

  4. In the Applications Navigator, click New Application.

    New Application option
  5. In the New Gallery, select General | Applications and choose Database Application as the Item.

    The New Gallery

    Click OK.

  6. In the Create Database Application dialog, change the Application Name from Application1 to DBModeling and type oracle as the Application Package Prefix. Notice that the Directory Name automatically changes to match the new Application Name.

    The Create Database Application dialog

    Then click Next.

  7. In Step 2 of the Wizard enter LogicalModel as the Project Name and select Database Modeling from the Project Features pane.

    The Create Database Application dialog

    Click Finish.

  8. The Application Navigator should look like the following:

    The Application Navigator
    When you work in JDeveloper, you organize your work in projects within applications. Show more or lessRead more...

    JDeveloper provides a number of predefined templates which enable you to create applications and projects that are configured for developing different types of applications.

    The templates provide the environment for the basic range of technologies supported by JDeveloper. You create your working environment by selecting the template that best fits your needs and then configuring it to add any additional technologies you intend to use.

    The options available to you in the New Gallery and for some context menu operations, depend on your template selection for that application.
  9. Save your work by clicking Save All Save All icon. You should save your work at regular intervals as you progress through the rest of the tutorial.

Step 2: Set the Environment for Class Model Diagrams

In this section, you set preferences for the class diagram environment. You can customize the way the class diagram components appear and respond to your specific needs. To prepare the class diagram environment, perform the following steps:

  1. Right-click the LogicalModel project in the Application Navigator and choose New from the context menu to display the New Gallery.

    The LogicalModel project in the Application Navigator
  2. In the New Gallery, click the All Features tab and in the Categories list, expand the General node if it is not already expanded, and select Diagrams. Then select Class Diagram from the Items list and click OK.

    The New Gallery
  3. In the Create Class Diagram dialog, change the Name to Logical Database and the Package name to logicalmodel, then click OK.

    The Create Class Diagram dialog

    A new database diagram opens.

  4. To set some class diagram preferences, select Tools -> Preferences.

    The Main menu Tools Preferences options
  5. In the Preferences dialog, select Diagrams -> Class, then in the Edit Preferences for, choose Class, and uncheck Show Operations as you are doing logical DB modeling and you don’t need operations.

    The Preferences dialog
  6. In the same dialog, click the Attributes tab, and check Show Visibility and turn off Sort Alphabetically.

    The Preferences dialog

    Click OK. These preferences are now set for all Class diagrams.

  7. Click the Save All button Save All icon to save your work.

  8. Notice the Component Palette to the right of the diagram area. You can use the Component Palette to add classes and related elements to your class diagram.
    (If the Component Palette is not visible, open it by choosing View | Component Palette from the main menu.)

    The Component Palette
Step 3: Create a Class Model Diagram

The following image shows the classes you are about to create: Employee, Department, and Location.

The Class Model to design

To create the above diagram, perform the following steps:

  1. In the Component Palette, select the Class component Class Icon in component palette and drag and drop it it onto the diagram.

    Class selection in the Component Palette
  2. Change the name to Employee.

    The Employee class
  3. Repeat the above operation to create 2 additional classes named Location and Department.

    Class diagram
  4. Using 'in place' edit, add attributes to the classes. Click inside the Employee class to create an attribute placeholder, (the new item will be  blue), click again to enter edit mode (don’t double click) and over-write the existing text with empno : Number.

    The Employee class
  5. Repeat the above operation to create the attributes per the following image (name: String, salary: Number and hours worked: Number)

    The Employee class
  6. Double-click within the Employee class to edit the properties. Expanding the Owned Attribute node shows the created attributes.

    The Employee class  properties
  7. Expand the node of one of the attributes, for example the empno node and explore the various definable properties.

    The Employee class  properties

    Click OK to exit.

  8. In the Component Palette, click the Directed 1 to * Association icon Directed association icon, then click within the Department class and keeping pressed, draw a line to the Employee class and click.

    The Class diagram
    Association between classes is bi-directional by default. Show more or lessRead more...

    You can define the flow of the association by using a directed association. The direction of the arrowhead identifies the container-contained relationship.
  9. Double-click the association to open the Properties dialog and expand the Owned End node. Rename endDepartment as made up of, and rename the endEmployee as member of.

    The Association Properties

    Click OK.

  10. Your diagram should look like the following:

    The Class Diagram
  11. Create a * to * Association Many to Many Association between Location and Department, and using 'in place' edit this time, rename the ends department and location. Refer the the previous steps if you need help.

    The Class Diagram Then Arrow The Class Diagram
  12. Using 'in place' edit, within the Location class, add 2 attributes area : String and country : String.

    The Location Class
  13. Double-click the Department class to open the Properties dialog.

    The Department Class
  14. Select the Owned Attribute node and click the Add button Add button. Select the Property option from the list.

    The Department Class Properties
    The Port option is a a specialization of the Property option. Show more or lessRead more...

    The Port option is part of the UML standard specification. It is not used in Class attributes, but as it is part of the UML specification it is listed as an option here.
  15. In the Properties pane, type group as the Name and String as the Type.

    Attribute properties
  16. Repeat the same operations to add a new attribute named name and of type String.

    Attribute properties

    Click OK.

  17. Click the Save All button Save All icon to save your work.

  18. Your diagram should look like this:

    The Class Diagram
Step 4: Enhance the Class Model

Employees are either full time employees or part time employees. Hours worked only concern part time employees. You want to represent these categories of employees on your class diagram using Generalization. You see that Generalization can be represented in different ways.

To enhance the diagram with categories of employees, perform the following steps:

  1. Select Employee and resize it to enlarge the box.

    The Class Diagram
  2. From the Component Palette, add a new Class Class icon to the diagram and name it Full Time.

    The Class Diagram
  3. Select the Full Time class and move it within the Employee class.

    The Class Diagram
  4. Using the Generalization Generalization incon icon from the Component Palette, draw a line from the Full Time class to the Employee class.

    The Class Diagram
    In UML modeling, a generalization relationship is a relationship in which one model element (the child) is based on another model element (the parent).Show more or lessRead more...

    You can add generalization relationships to capture attributes, operations, and relationships in a parent model element and then reuse them in one or more child model elements.

    Because the child model elements in generalizations inherit the attributes, operations, and relationships of the parent, you must only define for the child the attributes, operations, or relationships that are distinct from the parent.

    The parent model element can have one or more children, and any child model element can have one or more parents. It is more common to have a single parent model element and multiple child model elements.
  5. From the Component Palette, create a new Class Class icon on the diagram and name it Part Time.

    The Class Diagram
  6. Using the Generalization Generalization incon icon from the Component Palette, draw a line from the Part Time class to the Employee one. The two generalizations represent the possible ways an employee may work.

    The Class Diagram
    Employee is the generalization class for Part Time and Full Time. Show more or lessRead more...

    You can also implement this concept in a 'Database oriented representation' using subtypes within the Employee class.

    Even if the model can accept having a mixed representation of generalization using in and out combination, it is recommended to choose a convention ('all in' or 'all out') and stick with it consistently to make the models more readable.
  7. Select the Part Time class and drop it within the Employee one. From the previous representation, the two subclasses within the super-class is just a visual effect. There is no semantic change to the model.

    The Employee class in the Class Diagram

    In database modeling terminology these are known as two subtypes of Employee.

  8. Since only Part Time employees are concerned by the hours worked attribute, select it and drag it within the Part Time sub category.

    The Employee class in the Class Diagram
  9. Your diagram should now look like the following:

    The Class Diagram
  10. Select the directed association between Employee and Department, and in the property Inspector, check the Display Options: Show Name. This displays the Association name (Association1) on the diagram.

    The Class Diagram
  11. In the property Inspector, type emps in dept as the name.

    The Property Inspector
  12. Select the association between Department and Location and check the Show Name option in the property inspector.

    The Property Inspector
  13. This time, using 'in place' edit, rename the association to department locations.

    The Class Diagram
  14. Your diagram should now look like the following:

    The Class Diagram
  15. Click the Save All button Save All icon to save your work. Your Logical class model is defined now.

Bookmark Print Expand all | Hide all
Back to top
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.