Java Reference
In-Depth Information
Generating a Mapping File
Hibernate Tools provides a wizard to make the creation of the boilerplate XML mapping file
contents simpler. You can access the wizard via the File ä New ä Hibernate XML Mapping
File menu option from within the Hibernate Console perspective.
This brings up a standard Eclipse view in which you select the name and location of the
generated mapping file.
Clicking Next then brings you to a dialog that requires you to enter the fully qualified name
of the class that the mapping file will represent.
If you cannot recall the specific package and class name details, you can use the Browse
button to select the class from the class hierarchy.
The boilerplate mapping file will be created in the appropriate location. The wizard does
not currently populate this with any of the property or association mapping details. The gen-
erated file is therefore incomplete and can only be used as a skeleton to be filled in manually.
The sample output for our example Bookshelf class (which is not annotated) follows.
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.hibernatebook.tools">
<class name="Bookshelf">
</class>
</hibernate-mapping>
The Hibernate Tools plug-in for Eclipse includes an editor for its various mapping files that
provides context-sensitive completion—this is based upon the Web Tools Platform's (WTP) sup-
port for XML files, but adds awareness of mapping file details beyond the support for the basic
DTD description that WTP provides.
Generating a Configuration File
Hibernate Tools provides another wizard to aid in the creation of a Hibernate configuration
XML file. This wizard is accessed from the File ä New ä Hibernate Configuration File menu
option from within the Hibernate Console perspective.
This wizard prompts you (as with the mapping file wizard) to specify a path and file name
for the generated configuration file. You don't want to overwrite the configuration file used by
our sample application, so for this exercise, specify a file name of example.hbm.xml in the root
of the project directory.
Clicking the Next button will then take you to the dialog shown in Figure B-22, in which
all the basic configuration properties can be specified. When possible, a set of default options
are provided as combo box lists. The “Database dialect” field presents the dialects in a more
human-readable format, and also filters the Driver class and Connection URL fields to the
likely options.
Search WWH ::




Custom Search