Creating object model from entity model
- Download Computer Sales.vpp. You can also find this file at the bottom of this tutorial, under the Resources section.
- Open the downloaded project file in Visual Paradigm. You can open a project by selecting Project > Open from the application toolbar.
- 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.
- 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.
- 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.
- The Synchronize from Entity Relationship Diagram to Class Diagram window appear. Enter Class Model as the class diagram name and click OK.
- The Synchronize to Class Diagram screen appear. We just keep the class and attribute names as suggested. Click OK to continue.
- A class diagram is produced, based on the ERD.
Generating ORM Source and Hibernate Mapping
- 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.
- To generate Hibernate mapping, select Tools > Hibernate > Generate Code... from the application toolbar.
- In the Database Code Generation window, specify the output path of source files, Hibernate mapping files, DDL and library files.
- Click OK to start the generation.
- Let's take a look at the generated files.
- The source files are placed at ${outputPath}\src.
- Let's open the generated source file.
- The Hibernate mapping files are placed at ${outputPath}\src\ormmapping.
- Let's open the generated Hibernate mapping file.
Resources
Trademark Disclaimer
Oracle is U.S. registered trademark of Oracle Corporation