Peel me a Grape :: We make things work

Hibernate Annotator (H8A8) (Java)

Generate Hibernate mapping xml files from (Java 5) annotated classes. H8A8 is intended as an alternative to XDoclet for Hibernate for those working with Hibernate 3 under Java 5.

H8A8 is an alternative to the Hibernate Annotations project. The Hibernate Annotations project uses annotations from the EJB3 specification and doesn’t currently (summer 2005) allow the use of all hibernate features.

H8A8 instead makes available (nearly – see javadoc for details) all the mapping options currently available in Hibernate’s xml mapping format as Java 5 annotations. Moving to H8A8 from hand-written mapping xml files or xdoclet-generated mapping files should be reasonably straightforward.

Download

This current release is 0.2-preview. The API won’t change significantly from what it is now. The next release will probably be 1.0.

H8A8 is released under a BSD License

Download binary, source and documentation

Example of generated mapping file

The following code:

@H8Class(table="SUBCATEGORY")
public class SubCategory
{
    @ManyToOne private Category parentCategory;
    @Id(generator=@Generator("identity")) private Long id;
    @Property private String name;
    @Property private String description;

    @H8Set(
                    orderBy = "boost dest, briefDescription asc",
                    key = @Key(column = "parentSubCategory"),
                    value = @CollectionValue(otm = @OneToMany())
                 )
    private Set<Product> items = new HashSet<Product>();
}

generates (at run-time or compile-time) the hibernate mapping:

<hibernate-mapping>
  <class name="ie.scoilbuy.business.catalogue.SubCategory" table="SUBCATEGORY">
    <id name="id">
      <generator class="identity"/>
    </id>
    <property name="name"/>
    <property name="description"/>
    <many-to-one name="parentCategory"/>
    <set name="items" order-by="boost desc, briefDescription asc">
      <key column="parentSubCategory" />
      <one-to-many class="ie.scoilbuy.business.catalogue.Product"/>
    </set>
  </class>
</hibernate-mapping>

Changes

Since 0.1-preview (May 2005), the main changes are:

  • Repackaging. Collection annotations have a separate package, as does custom SQL
  • Documentation. A lot of extra javadoc added.
  • Completeness. Covers the majority of the possible hibernate-mapping files (except dynamic-components)
  • Project moved to http://code.google.com/p/h8a8/ (February 2007)

Support

Questions or comments about h8a8: Email us at h8a8@peelmeagrape.net or log an issue. Questions on hibernate, hibernate mapping etc.: Hibernate support forums.

Documentation

Javadoc included in the distribution contains instructions for installation and usage.

How does it work?

All the annotations in the net.peelmeagrape.hibernate package are themselves annotated using custom meta-data. There is, in effect, 2 levels of meta-data: the annotations on your classes, which specify hibernate mapping information, and (meta-meta-data) annotations on those annotations, which specify how to generate the mapping xml.

The HibernateAnnotationsProcessor processes your class using reflection and generates a dom4j tree containing the hibernate mapping document.

This approach allowed h8a8 to be developed reasonably easily – the majority of the source is metadata, which maps very closely onto the hibernate-mapping DTD.