Tools

Previous: Debugging

There are a multitude of different tools out there for generating Hibernate code: the list includes (but is not limited to) the Hibernate Tools project, Hibernate Synchronizer and MyEclipse's Hibernate capabilities. Furthermore, many claim to support round-trip code generation - the ability to allow you to update a database schema and then regenerate domain objects without overwriting any business-related code you might have added to them.

In our experience, it's best not to get too hung up on tools. They can be useful for one-off code generation if you are dealing with a large schema and/or large tables. However, tools never quite generate what we actually want and thus the generated code requires modification. Round-trip generators have stringent requirements about how you modify the code and often it's just not worth the fuss.

Furthermore, in our experience many tools will behave strangely if the database schema is at all unusual. For example, if you use the Hibernate Tools to generate a domain object for a table with no primary key, it will assume that the whole table is the primary key and generate a composite primary key accordingly.

Finally, round-trip engineering is often more trouble than it's worth - if it works at all.

Hibernate Tools

All that said, tools can have their uses. One of the best things we've seen is the Hibernate Tools ability to prototype queries via a HQL editor. Furthermore, the results are displayed in a tree format that you can explore at your leisure. It will also log the generated SQL. It should be noted that we were using beta 3 of Hibernate Tools and it was somewhat unstable. At the time of writing, it was at beta 5. Thus, as with other tools, we'd encourage you to give it a go but not get too hung up if it doesn't work.

Next: Annotations