Hibernate Annotations

1. Java 1.5 only

Only Java 1.5 supports annotations. If you are using 1.4 you can use xdoclet to help generated your mapping files


2. Basic column mapping

unique column restraint

To specifiy an unique key constraint on a column use



Enums are saved as either text or ordinals depending on the underlying column.

Ignored or transient fields

To ignore the field, annotate it with @Transient so it will not be mapped by hibernate.

3. Cascade all-delete-orphan

The standard EJB annotations don't have the delete orphan option.

@OneToMany {cascade=CascadeType.ALL}

The above is from the javax.persistence package.

Instead we can still use the original Hibernate mapping attributes this way: