Sequence grouping for container-managed persistence in assembled EJB modules
After assembling an Enterprise JavaBeans (EJB) module that contains container-managed persistence (CMP) beans, you can prevent certain types of database-related exceptions from occurring during application run time. Using sequence grouping, you can specify the order in which entity beans update relational database tables.
Eliminate exceptions resulting from referential integrity (RI) violations
- Entity bean creates and remove operations correlate to the database immediately upon method invocation.
- Entity bean changes are cached by the EJB container until either a finder method is called, or the transaction ends.
The only way to guarantee a persistence sequence that honors database RI is to designate the sequence, which you do in the EJB deployment descriptor editor of the assembly tool. Through the sequence grouping feature, you assign beans to CMP groups. Within each group, you specify the order in which the persistence manager inserts bean data into the database to accomplish updates without violating RI.
See the Setting the run time for CMP sequence groups topic for detailed instructions on designating sequence groups. Consult your database administrator about the RI policy with which you need to synchronize.
Minimize exception risk for optimistic concurrency control schemes
- When concurrent transactions attempt to lock the same table row, database deadlock occurs.
- Transactions can occur in an order that violates application logic.
Use the sequence grouping feature to order bean persistence so that these scenarios are less likely to occur.