Hibernate Roundtrip Development
 The tools used for roundtrip development provide support for transforming to and from sourcecode (java), mappingfiles (hbm) and a database definition (ddl). The goal of these tools is to help support the usage of Hibernate in almost any kind of development scenario. For example, if you start with an existing (legacy) database, use the tools to generate Hibernate mapping files and Java source files. If you start with Java code, you can markup your classes with XDoclet tags and automatically generate Hibernate mapping files from your annotations. Of course, you can also generate a SQL database schema (DDL) automatically from a Hibernate mapping. Note, that not all tools provide complete support for all features in Hibernate, as it is simply not possible to generate every output from every input (for example, a database schema doesn't have enough information to generate perfect Java classes). See the illustration on the right to get an overview of the roundtrip process and the tools used in each step. AndroMDA: This tool can use XML files in the XMI format (generated by UML modeling tools such as Poseidon/ArgoUML) and generate Java source files automatically. Use it to generate the POJO classes of your domain model, documentation can be found in the Community Area and on the AndroMDA website. XDoclet: With XDoclet, you place annotations right in your Java source files (in Javadoc comments). XDoclet will then read this markup and generate Hibernate mapping files automatically. The defaults are reasonable for most cases, this procedure therefore minimizes typing. You can of course also merge/add your own mapping files in the process. Note that XDoclet does (conceptually) not support some more exotic Hibernate mappings (entity associations with composite keys, for example). See the XDoclet documentation in the Community Area for an example and the XDoclet website for downloads and more information. SchemaExport (hbm2ddl): This tool is provided with the core Hibernate download. It uses Hibernate mapping metadata XML files to generate a SQL database schema with DDL. You can enhance your mapping files with database specific elements (SQL column datatypes, unique/check constraints/indexes, etc.) and then export the SQL DDL to a text file. You may also directly export the DDL to a database, this is very powerful in development, as you can automatically create and drop a database at each test run. See the Hibernate reference documentation for more information about this tool. Middlegen: If you have a legacy database, Middlegen is the right tool for you. With the Hibernate plugin, Middlegen can generate Hibernate mapping files. You may also customize the mapping files with a GUI. See the Middlegen website for more information. CodeGenerator (hbm2java): This tool is part of the separate Hibernate Extensions download. It reads Hibernate mapping XML files and generates Java code for your domain/business and persistence layer (finder method generation). It is extremely flexible and can even be customized with Velocity templates. A nice trick is to automatically generate XDoclet Javadoc tags, so you will have a full roundtrip cycle starting from the top again. See the Hibernate reference documentation for more information. You may also find references to some older tools, such as class2hbm and ddl2hbm. They have been replaced by the more powerful XDoclet and Middlegen and are considered deprecated. If you still like to use them, see the Hibernate reference documentation and the Hibernate Extensions package. If you want to get started quickly with Hibernate roundtrip development, have a look at the Toolset Workshop.
|