Generating ORM code from class diagram
- Select Tools > Hibernate > Generate Code… from the toolbar. This opens the Database Code Generation window.
- Select the (programming) language of your project.
- Specify the output path of the generated code.
- Configure the code generation options. Read the next sections for details about those available options.
- Click OK. The Generate ORM Code/Database dialog box will appear, indicating the progress of code generation. Click Close when complete. If succeed, you can find the generated source files in the folder specified in the Output Path field.
Overview of Database Code Generation
|Generate||Code and Database – generate both ORM code and database.
Code only – generate only ORM code but not database.
Database only – generate only database but not ORM code.
|Language||The language of your application to be developed. Just leave it as-is if you are uncertain or not going to develop any applications.|
|Output Path||The folder to store the generated DDL files, source files and library files (if any).|
|Deploy To||Specify the template setting for the purpose of the generated code. This setting affects the generated optional Jar and Datasource setting in database connection. You can select Standalone Application, WebLogic Application Server 8.1/9.0, WebSphere Application Server Community Edition 1.0, JBoss Application Server and Generic Application server.|
|Framework||Select between Hibernate XML or JPA.|
|Logging||Select how to log exceptions, either do not show, print to error stream or print to log4j.|
|Default Lazy Collection Initialization||Lazy initialization avoids objects in collection from being loaded unnecessarily when the main object is being loaded.|
|Default Lazy Association Initialization||Lazy initialization avoids associated objects from being loaded unnecessarily when the main object is being loaded.|
|Association Handling||Select the type of association handling to be used, either Smart or Standard.
|Persistent API||Select the type of persistent code to be generated, either Static Methods, Factor Class, DAO, POJO or Mapping Only.|
|Generate Criteria||Check this option to generate the criteria class for each ORM-Persistable class. The criteria class supports querying the database by specifying the searching criteria.|
|Cache Options||Click to choose a cache option.|
|Select Optional Jar||Click on the Select Optional Jar button, then select the libraries and JDBC driver to be included in the generation of the orm.jar file.|
|Advanced Settings||Click to specify the advanced settings.|
|Samples||Samples files, including Java application, servlet, servlet filter and Java Server Page (JSP) sample are available for generation. The generated sample files guide you through the usage of the Java persistence class. You can check the options to generate the sample files for reference.|
|Scripts||Check the options to generate the scripts, including Ant File, Batch and Shell Script which allow you to execute the scripts directly.|
|Generate Filter and Web Application Descriptor (web.xml)||Check this option to generate filter and web application description, which are useful in web application development.|