Visual Paradigm logo
Jump to Menu

Generate Hibernate Mapping for Oracle Database

Hibernate is a popular and high performance object/relational persistence Java development framework. Visual Paradigm provides comprehensive development environment for Java developers to design and generate persistence layer. This tutorial shows you how to transform database design, which is the ERD, to class diagram, and eventually generate source files and Hibernate mapping layer from it.

Compatible edition(s): Enterprise, Professional, Standard

  • March 16, 2016
  • Views: 18,185
  • PDF

>

Creating object model from entity model

  1. Download Computer Sales.vpp. You can also find this file at the bottom of this tutorial, under the Resources section.
  2. Open the downloaded project file in Visual Paradigm. You can open a project by selecting Project > Open from the application toolbar.
  3. Before we continue, there is one important point to note here. In this tutorial we are going to generate ORM code and Hibernate mapping that can work with an Oracle database. It is important to configure database setting by selecting Oracle as your database. Let's check. Select Tools > DB > Database Configuration... from the application toolbar. We have selected Oracle for you in the Database Configuration window. Do remember to do this yourself in real case. Besides, make sure you have entered the connection details as well in real usage. But to complete this tutorial, we can leave the connection settings unfilled. Let's close the Database Configuration now.
    Database Configuration
  4. Open the Entity Relationship Diagram (ERD) Computer Sales and take a look. The diagram contains a number of entities related to an ordering system designed for storing computer sales records.
    Entity Relationship Diagram example
  5. In order to generate the Hibernate mapping and ORM source files, you need to synchronize the ERD and class diagram first. Right click on the ERD and select Synchronize to Class Diagram.
  6. The Synchronize from Entity Relationship Diagram to Class Diagram window appear. Enter Class Model as the class diagram name and click OK.
    Synchronize ERD to Class Diagram
  7. The Synchronize to Class Diagram screen appear. We just keep the class and attribute names as suggested. Click OK to continue.
    Modify class and attribute names
  8. A class diagram is produced, based on the ERD.
    Class diagram formed from ERD

Generating ORM Source and Hibernate Mapping

  1. There is a package header on top of the diagram, on the left hand side. The package header specifies the package where the classes under this diagram are stored. It affects both the structuring of model and the generated code. Without specifying any package header there, classes will all be placed at root, both in model and in generated code. Let's enter a package name. Double click on the package header and enter com.computersales as package header.
    Entering package header
  2. To generate Hibernate mapping, select Tools > Hibernate > Generate Code... from the application toolbar.
  3. In the Database Code Generation window, specify the output path of source files, Hibernate mapping files, DDL and library files.
    Specifying output path
  4. Click OK to start the generation.
  5. Let's take a look at the generated files.
    Browse generated files
  6. The source files are placed at ${outputPath}\src.
    File list of generated code
  7. Let's open the generated source file.
    Generated java code from ORM
  8. The Hibernate mapping files are placed at ${outputPath}\src\ormmapping.
    File list of generated <span class='notranslate'>Hibernate</span> map
  9. Let's open the generated Hibernate mapping file.
    Generated <span class='notranslate'>Hibernate</span> map file



Trademark Disclaimer

Oracle is U.S. registered trademark of Oracle Corporation


Turn every software project into a successful one.