Skip to content

Hibernate Annotations

Annotations are supported in Java 1.5 and later. If you are using 1.4 you can use XDoclet to help generate your mapping files.

To specifiy an unique key constraint on a column use

@Column(unique=true)

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

To prevent persistence of a field, annotate it with @Transient so it will not be mapped by hibernate.

The standard EJB annotations do not have the delete orphan option.

@OneToMany {cascade=CascadeType.ALL}

The above is from the javax.persistence package.

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

@org.hibernate.annotations.Cascade(
{org.hibernate.annotations.CascadeType.ALL,org.hibernate.annotations.CascadeType.DELETE_ORPHAN}
)