Java Reference
In-Depth Information
CHAPTER 7
n n n
Creating Mappings with
Hibernate XML Files
I n the simple example programs in Chapters 1 and 3, we demonstrated how a mapping file
could be used to establish the relationship between the object model and the database
schema. A mapping file can map a single class or multiple classes to the database. The map-
ping can also describe standard queries (in HQL and SQL) and filters.
Hibernate Types
Although we have referred to the Hibernate types in passing, we have not discussed the ter-
minology in any depth. In order to express the behavior of the mapping file elements, we
need to make these fine distinctions explicit.
Hibernate types fall into three broad categories: entities, components, and values.
Entities
Generally, an entity is a POJO class that has been mapped into the database using the <class>
or <subclass> elements.
An entity can also be a dynamic map (actually a Map of Map s). These are mapped against
the database in the same way as a POJO, but with the default entity mode of the
SessionFactory set to dynamic-map .
The advantage of POJOs over the dynamic-map approach is that compile-time type safety
is retained. Conversely, dynamic maps are a quick way to get up and running when building
prototypes.
It is also possible to represent your entities as Dom4J Document objects. This is a useful
feature when importing and exporting data from a preexisting Hibernate database, but it is
not really central to the everyday use of Hibernate.
We recommend that you use the standard entity mode unless you need to sacrifice accu-
racy for timeliness, so the alternate approaches are not discussed in this chapter—however,
we give some simple examples of the Dom4J- and Map -based mappings in Appendix A.
139
Search WWH ::




Custom Search