2.4.7. Cascade

Hibernate offers more operations than the Java Persistence specification. You can use the @Cascade annotation to cascade the following operations:
  • PERSIST
  • MERGE
  • REMOVE
  • REFRESH
  • DELETE
  • SAVE_UPDATE
  • REPLICATE
  • DELETE_ORPHAN
  • LOCK
  • EVICT
This is especially useful for SAVE_UPDATE (which is the operation cascaded at flush time if you use plain Hibernate Annotations - Hibernate EntityManager cascade PERSIST at flush time as per the specification). DELETE_ORPHAN applies only to @OneToMany associations, and indicates that the delete()/remove() operation should be applied to any child object that is removed from the association. In other words, if a child is dereferenced by a persistent parent and if DELETE_ORPHAN is used, the "orphaned" child is deleted.
@OneToMany( cascade = {CascadeType.PERSIST, CascadeType.MERGE} ) @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
public Collection<Employer> getEmployers()
It is recommended to use @Cascade to compliment @*To*(cascade=...) as shown in the previous example.