This chapter is composed of :
The purpose of this chapter is to show how to generate Hibernate Java classes.
This wizard needs to use a target Java Project.
This wizard is an integration of the separate Hibernate Extensions hbm2java.
EclipseDatabase provides the current embedded Hibernate Extensions API.
To start the Hibernate Java Resources wizard, select :
File->New->Other->Database->Database Hibernate Resources
or
Select an object in the Package Explorer View or the Navigator View then right-click and select :
New->Other->Database->Database Hibernate Resources
The selection is contextual.This means that if you select an existing Hibernate Configuration file.
The wizard will be opened with a selected Hibernate Configuration file if applicable.
Otherwise :
The wizard will be opened without any selected Hibernate Configuration file.
You can run this wizard in another way.
Select a set of Hibernate Mapping file definitions, right-click and select :
Create Hibernate Java Resources
However the Configuration selector will not be available.
Type in the Java Source Folder text field the targeted Java Source Folder.
The Java Source Folder should exist.
Otherwise use the Browse button :
Select the appropriate Java Source Folder.
Use the Browse button :
Select the appropriate Hibernate Configuration file.
You can set various Hibernate options.
2.3.1. Generate Hibernate Code
The hbm2java Hibernate code generator works in two ways :
The first one is an internal code generator, Basic Renderer.
The second one uses a Velocity template, Velocity Renderer.
This code generator is the preferred Hibernate code generator.
2.3.1.1.1. Generate Empty Concrete Classes
With this option, the wizard will generate two sets of classes:
- one set of Abstract classes.
- one set of Concrete classes.
With this option you will obtain a clean separation between your code and the generated code.
2.3.1.1.2. Generate Basic Finder
With this option, the wizard will generate three sets of classes:
- one set of Abstract classes.
- one set of Concrete classes.
- one set of Finder classes.
With this option you will obtain a clean separation between your code and the generated code.
2.3.1.2. Use Velocity Renderer
Below your Plugin Templates or MyTemplates you should see the following file:
Hibernate/pojo.vm
If checked, the wizard will use this velocity template to generate Hibernate Java classes.
2.3.2. Generate Stateless Session Bean
The hbm2java tool contains a Stateless Session Bean generator.
This generator uses as its input a set of Hibernate files.
You can use an optional xml file to configure this wizard.
Below your Plugin Templates or MyTemplates you should see the following file:
If checked, the wizard will use this hbm2java.config.xml file.
The Browse button lets you locate an .xml file.
Usually you locate hbm2java.config.xml file.
The code generation process will be performed in the targeted Java Source Folder.
Detailed information will be displayed in the DatabaseConsole window.