|  |  |  | License Codehaus OpenEJB OpenJMS OpenORB Tyrex

Old releases
General
Release 1.3
Release 1.3rc1
Release 1.2

Main
Home
About
Features
Download
Dependencies
Reference guide
Publications
JavaDoc
Maven 2 support
Maven 2 archetypes
DTD & Schemas
Recent HTML changes
News Archive
RSS news feed
Project Wiki

Development/Support
Mailing Lists
SVN/JIRA
Contributing
Support
Continuous builds
Prof. services

Related projects
Spring ORM support
Spring XML factories
WS frameworks

XML
XML

XML Code Generator
XML Code Generator

JDO
Introduction
First steps
Using JDO
JDO Config
Types
JDO Mapping
JDO FAQ
JDO Examples
JDO HOW-TOs
Tips & Tricks
Other Features
JDO sample JAR

Tools
Schema generator

Advanced JDO
Caching
OQL
Trans. & Locks
Design
KeyGen
Long Trans.
Nested Attrs.
Pooling Examples
LOBs
Best practice

DDL Generator
Using DDL Generator
Properties
Ant task
Type Mapping

More
The Examples
3rd Party Tools
JDO Tests
XML Tests
Configuration

About
License
User stories
Contributors
Marketplace
Status, Todo
Changelog
Library
Contact
Project Name

## How to cascade update

Overview
Enabling cascading update
Scenarios
db.update()
Limitations
See also

## Overview

When working with long transactions, you can cascade the db.update() operation, so that, for example, updating the root of a large object graph causes all connected entites to update as well (provided cascading update is enabled on the particular relationships, of course).

## Enabling cascading update

To enable cascading update on a relationship you simply set the cascading attribute of the <sql> field describing the relation to "update" (or "all"):

    <field name="book" type="myapp.Book" >
      <sql name="book_id" cascading="update" />
    </field>

In case of bidirectional relationships, be aware that it matters on which end you enable cascading update. It is also possible to enable it on both ends.

## Scenarios

### db.update()

Let's say we have the objects Author and Book and they are in a one-to-one relationship, with every Book having exactly one Author. The database looks like this:

Author

id | name
--- | ---
1 | "John Jackson"

Book

id | title | author_id
--- | --- | ---
1 | "My Life" | 1

Now let's change the book's title. Note that we never directly load the book and that the change happens outside of any transaction:

    db.begin();
    Author a1 = db.load(Author.class, 1);
    db.commit();

    a1.getBook().setName("My Fantastic Life");

    db.begin();
    db.update(a1);
    db.commit();

Afterwards, the database looks like this:

Author

id | name
--- | ---
1 | "John Jackson"

Book

id | title | author_id
--- | --- | ---
1 | "My Fantastic Life" | 1

## Limitations

- | To-many relationships are currently not supported (except many-to-one).
- | As it is now, enabling cascading update will cause db.update() to also create any entities that have not yet been persisted. (In other words: setting cascading to "update" has the same effect as setting it to "update create", but only when invoking db.update().)

## See also

- | How to use cascading operations - overview

<notice> Copyright © 1999-2005 ExoLab Group, Intalio Inc., and Contributors. All rights reserved. </notice>
<notice> Java, EJB, JDBC, JNDI, JTA, Sun, Sun Microsystems are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and in other countries. XML, XML Schema, XSLT and related standards are trademarks or registered trademarks of MIT, INRIA, Keio or others, and a product of the World Wide Web Consortium. All other product names mentioned herein are trademarks of their respective owners. </notice>