Annotations

Previous: Tools

We highly recommend the use of Hibernate Annotations. The chief benefit for us has been that domain objects don't have an XML mapping file anymore - only an annotated Java file. This makes maintenance much easier. It also means that automatic refactoring tools can more easily work on your code.

An important thing worth realising about Hibernate Annotations is that they use the annotations defined in the EJB3 specification. This means that they're not going to go away in a hurry.

However, there are a number of important factors you should be aware of before you use annotations:

  • It requires Java 5. You may not be able to use this in your production environment.
  • At the time of writing, it was still in pre-release. Your client may not be comfortable with you using pre-release software in production. That said, with the finalisation of the EJB 3 specification, it is very close to release. Furthermore, in our experience the software has been very stable.
  • It has a steep learning curve. This is primarily because the documentation is not as mature. If you're new to Hibernate, using annotations can exacerbate your learning difficulties.
  • Tools support is a little behind (although the Hibernate Tools have been successfully used to generate annotated domain objects).

Note also that when using Hibernate Annotations, EJB 3 child-parent relationships are eager-fetched by default. This differs from the way Hibernate behaves if you are using mapping files.

Next: Deployment