| Sign In/My Account | View Cart |
Hibernate is a popular
open source library for handling object/relational persistence and
queries. In Hibernate, mapping between database tables and POJO
("plain old Java objects") classes is configured in a set of XML
mapping files. hbm2java is a code generator that
converts the mapping files into POJOs. It is part of the Hibernate Tools subproject
and can be downloaded in the separate
Hibernate Extensions package.
Several strategies exist for managing Hibernate mapping files, such as:
xdoclet
tags in your Java classes and generating the corresponding mapping
file.hbm2java tool.In this article, we will look at this last approach. Although such choices are often a matter of taste, this approach does has several advantages in many situations:
In this approach, the Hibernate mapping files are king. All
Hibernate mapping information is centralized in these files,
meaning no annotations are used in the source code. All persistent
classes are generated using the hbm2java tool. The
classes cannot be modified afterwards.
This process is illustrated in Figure 1. First, you take the set
of Hibernate mapping files. You may also need a hbm2java
configuration file, generally called hbm2java.xml. Using
these two entries, the hbm2java tool generates one or
more Java classes for each Hibernate mapping file. The hbm2java
configuration file can be useful for fine-tuning the
class-generation process. (In Hibernate 3, this file is no longer
used.)
Figure 1. Generating Java classes from the Hibernate mappings
using hbm2java
|
Related Reading Hibernate: A Developer's Notebook |