Chapter 3. Starting from Java
Combining Hibernate with XDoclet makes it possible to start from Java code when building an application. Using XDoclet markup tags (similar to the tags used by javadoc), you can generate the *.hbm.xml files required by Hibernate directly from your Java source files.
XDoclet, available from http://xdoclet.sourceforge.net/, is an open-source framework for annotating Java source files with special comments, which are then used to construct configuration files used by a variety of different environments.
Many developers first encounter XDoclet when working with EJB 2.X as a tool to help manage the complexity of EJB 2.X development. XDoclet-style annotations have become so popular that support for similar annotations (as described by JSR 175, http://jcp.org/en/jsr/detail?id=175) is included as a standard extension in the upcoming release of Java (Java 2 Platform, Standard Edition 5.0). The early draft specification for EJB 3.0 uses annotations in lieu of XML descriptors. The upshot is that the use of XDoclet and Hibernate is (as of this writing) a close approximation of the development model being suggested for EJB 3.0.
WARNING
There are three significant downsides to using annotations as your development solution. The first is the addition of (yet another) complex tool to your build process. The second is the relative difficulty of debugging and otherwise tracing the source of problems with the generated mapping file. The third downside of annotations is that configuration information is now stored directly in your Java source files. Given all of these downsides, I have found annotations to be much more error-prone and difficult to work with than simply starting from a mapping file, as described in Chapter 2.
In constructing the application in this chapter, we will start from a set of Java sources and then walk through the rest of the development path.
|