Book Image

EJB 3 Developer Guide

By : Michael Sikora
Book Image

EJB 3 Developer Guide

By: Michael Sikora

Overview of this book

Table of Contents (18 chapters)
EJB 3 Developer Guide
Credits
About the Author
About the Reviewers
Preface
Annotations and Their Corresponding Packages

Cascade Operations


Cascading can occur whenever we have relationships between entities. For example, there is a one-to-one relationship between the Customer and Referee entities in our application. By allowing a persist operation to cascade, whenever we persist a Customer entity, the associated Referee entity is automatically persisted. There is no need to persist the Referee entity in a separate operation. By allowing a remove operation to cascade, whenever we remove a Customer entity, the associated Referee is automatically removed.

Cacading can occur for one-to-one, one-to-many, many-to-one, and many-to-many relationships. Cascading is possible for persist, remove, merge, and refresh operations. There is no default cascading behavior for any operation and for any relationship.

persist

To cascade a persist operation, set the cascade element of the relationship annotation to CascadeType.PERSIST. For example, we could cascade a persist from the Customer to the Referee entity by modifying...