If you’ve worked with relational databases, you’ve no doubt encountered cascades. Cascades propagate certain operations on a table (such ORGANIZING YOUR MAPPING FILES as a delete) to associated tables. (Remember that tables are associated through the use of foreign keys.) Suppose that when you delete an Event, you also want to delete each of the Speaker instances associated with the Event. Instead of having the application code perform the deletion, Hibernate can manage it for you. Hibernate supports ten different types of cascades that can be applied to many-to-one associations as well as collections. The default cascade is none. Each cascade strategy specifies the operation or operations that
should be propagated to child entities. The cascade types that you are most likely to use are the following:
The cascade element is added to the desired many-to-one or collection element. For example, the following configuration instructs Hibernate to delete the child Speaker elements when the parent Event is deleted:
<pre>
<set name=”speakers” cascade=”delete”>
<key column=”event_id”/>
<one-to-many class=”Speaker”/>
</set>
</pre>
That’s all there is to configuring cascades. It’s important to note that Hibernate doesn’t pass the cascade off to the database. Instead, the Hibernate service manages the cascades internally. This is necessary
because Hibernate has to know exactly which objects are saved, updated, and deleted.