Annotations can be applied to a variety of Java elements. When working with Hibernate, you’ll most often be concerned with annotating classes and their fields, to specify how a model object is to be mapped to a database schema. This is analogous to the way our XML mapping documents were structured around mapped classes and their properties. That's enough background and explanation—let’s dive right in and make this concrete. Time to map the classes from the examples (as fully developed in Chapter 6) using annotations!
shows one way you could annotate the
class. This chapter will explain the basics of Hibernate Annotations,
but if you would like a more thorough description of some of these
annotations, please refer to the Hibernate Annotations project web site
at http://annotations.hibernate.org. To save pages, the listings of annotated classes are
compressed slightly from what you’ll find in the source
download—whitespace is condensed and the JavaDoc is omitted. Since these
are hand-written classes, not code-generated ones as they were in prior
chapters, there is room for much more comprehensive JavaDoc, so it’s
worthwhile to take a look at the downloadable versions, too.