Previous Next
sde_java_ee_user_guide Chapter 13 -Using ORM Wizard

Chapter 13 - Using ORM Wizard

An ORM Wizard is provided to you to generate persistent code and/or database either from database, class diagram or entity relationship diagrams. This chapter shows you how to activate the ORM Wizard and generate code and/or database by one of the three options provided by wizard.

In this chapter:

Introduction

Mapping objects to relational database is a complicated and error pound task in the development. Acting as a bridge between object model, data model and relational database, the mappings between these models are automated. Apart from these mappings, the mapping between object models and persistent code is also supported. Hence, the persistent code can thus map to the relational database.

The synchronization between persistent code, object model, data model and relational is supported, which reduces the development time for handling these tedious programming jobs between them. Moreover, your document will always keep up-to-date. To support synchronization in-between persistent code and relational database, you are allowed to generate database and persistent code for your development project.

An ORM Wizard for the generation of persistent code and database. The wizard provides you with three options:

  1. Generate Code from Database.
  2. Generate Code and Database from Entity Relationship Diagram (ERD).
  3. Generate Code and Database from Class Diagram.

To activate the Wizard:

  1. On the menu, click Modeling > ORM > Wizards....
  2. Figure 13.1 - To start the ORM Wizard

    For other SDE:

    SDE Method
    SDE for JBuilder On the menu, click Tools > Modeling > ORM > Wizards....
    SDE for NetBeans On the menu, click Modeling > ORM > Wizards....
    SDE for IntelliJ IDEA On the menu, click Modeling > ORM > Wizards....
    SDE for JDeveloper On the menu, click Model > ORM > Wizards....
    SDE for WebLogic Workshop On the menu, click Modeling > ORM > Wizards....
    Table 13.1
  3. A Wizard Welcome Page will be shown, select Language of the code to be generated from the drop-down menu, either Java or C#.
  4. Figure 13.2 - Select the programming language
  5. Select one of the wizard options, and then click Next to proceed.
  6. Figure 13.3 - Select the generate options

Generating Code from Database

Figure 13.4 - The workflow of generate code from database

Upon selecting the option for Generate Code from Database, the wizard helps you generate persistent code from database tables according to the requirements you specified throughout the wizard.

Follow the steps of the Generate Code From Database wizard:

  1. Database Configuration
  2. Selecting Tables
  3. Figure 13.7 - Select the Tables

    The database is connected based on your options in the previous database configuration option pane and all database tables are reversed. You are asked to select the database tables which you want to generate persistent class to manipulate those tables. By default, all the database tables are selected for the generation of code shown in the list of Selected Tables. You can deselect the table by using the list of buttons between the list of Available Tables and Selected Tables.

  4. Class Details Configuration
  5. Figure 13.8 - Class Detail Configuration

    After selecting tables, you will be directed to a Class Details Configuration pane. You are asked to define the Class Detail for generating code. The persistent classes will be generated based on the information defined here. You can edit the class details by double-clicking the field.

  6. Generate Code
  7. Click Finish, the Generate ORM Code/Database dialog box appears showing the progress of code generation. Click Close when the generation is complete.
  8. Figure 13.17 - Generate ORM Code/Database dialog

    A class diagram and an entity relationship diagram will be generated automatically and added to your project. The generated persistent code and required resources will be generated to the specified output path.

Generating Code and Database from ERD

Figure 13.18 - Generate code and database from ERD

Upon selecting the option for Generate Code and Database from ERD, the wizard helps you generate persistent code and database from ERD with respect to the requirements you specified throughout the wizard.

Take the following ERD as an example:

Figure 13.19 - Entity Relationship Diagram (ERD)

Follow the steps of the Generate Code and Database From ERD wizard:

  1. Class Details Configuration
  2. Figure 13.20 - Class Details Configuration

    You are asked to define the Class Details for generating code. The persistent classes will be generated based on the information defined here. You can edit the class details by double-clicking the field.

  3. Database Configuration
  4. Generate Code
  5. Click Finish, the Generate ORM Code/Database dialog box appears showing the progress of code generation. Click Close when the generation is complete.
  6. Figure 13.41 - Generate ORM Code/Database dialog

    A class diagram will be generated automatically and added to your project. The generated persistent code and required resources will be generated to the specified output path and the generated database will be set up to the specified database configuration.

Generating Code and Database from Class Diagram

Figure 13.42 -Generate Code and Database from Class Diagram

Upon selecting the option for Generate Code from Class Diagram, the wizard helps you generate persistent code and database from class diagram with respect to the requirements you specified throughout the wizard.

Take the following class diagram as an example:

Figure 13.43 - Class Diagram

Follow the steps of the Generate Code and Database from Class Diagram wizard:

  1. Selecting Classes
  2. Figure 13.44 - Select the ORM Persistable Classes

    You are asked to select the classes on the class diagram which you want to generate persistent class to manipulate persistent data. By default, all the classes stereotyped as ORM-Persistable on the class diagram are selected for the generation of code and database shown in the list of Persistable Classes. You can deselect the persistable classes by using the list of buttons between the list of Non Persistable Classes and Persistable Classes.

  3. Select Primary Key
  4. Figure 13.45 - Select the primary key

    You are asked to select the primary key for each class being mapped to data model and relational database. You can either select an attribute as the primary key or let SDE generate the primary key automatically by using the drop-down menu. For more information, refer to the description of Mapping Primary key in the section of Mapping an Object Model to a Data Model in the Object Model chapter.

  5. Table Details Configuration
  6. Figure 13.46 - Table Details Configuration

    You are asked to define the Table Details for generating database and code. The database and persistent classes will be generated based on the information defined here. You can edit the table details by double-clicking the field.

  7. Database Configuration
  8. Generate Code
  9. Click Finish, the Generate ORM Code/Database dialog box appears showing the progress of code generation. Click Close when the generation is complete.
  10. Figure 13.54 - Generate ORM Code/Database dialog

    An entity relationship diagram will be generated automatically and added to your project. The generated persistent code and required resources will be generated to the specified output path and the generated database will be set up to the specified database configuration.


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