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.



Enter your email address:

Delivered by FeedBurner



Sandeep Joshi
Mathematics, Technology and Programming are my passion. I am a part of Java Ecosystem and through this blog, I contribute to it. I am here to blog about my interests, views and experiences.
I am on Google+ and Facebook.
I feel proud to be listed as a "National Memory Record Holder" in the Limca Book of Records, 2009 and have attempted for an International Memory record in the Guiness Book of Records. I can remember the value of PI upto 10,000 digits after the decimal (3.1415.....). You can contact me on javagenious.com(At)gmal.com ; I would like to hear from you :)